-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
93 lines (90 loc) · 2.43 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
module.exports = env => {
if (env.prod === undefined) {
env.prod = true;
}
const sourceMap = !env.prod;
return {
entry: './src/index.jsx',
output: {
filename: 'main.bundle.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
abstracts: path.resolve(__dirname, 'src/abstracts/'),
base: path.resolve(__dirname, 'src/base/'),
components: path.resolve(__dirname, 'src/components/'),
layout: path.resolve(__dirname, 'src/layout/'),
pages: path.resolve(__dirname, 'src/pages/'),
logic: path.resolve(__dirname, 'src/logic/'),
utilities: path.resolve(__dirname, 'src/utilities/'),
testUtils: path.resolve(__dirname, './testUtils/'),
},
},
module: {
rules: [
{
test: /\.jsx$/,
exclude: /node_modules/,
use: [
'babel-loader',
{
loader: 'eslint-loader',
options: { emitWarning: !env.prod },
},
],
},
{
test: /\.s?css$/,
use: [
{
loader: env.prod ? MiniCssExtractPlugin.loader : 'style-loader',
options: {
sourceMap,
},
},
{
loader: 'css-loader',
options: {
sourceMap,
modules: true,
localIdentName: '[local]--[hash:base64:5]',
},
},
{
loader: 'sass-loader',
options: {
sourceMap,
},
},
{
loader: 'sass-resources-loader',
options: {
resources: ['./src/abstracts/global/*.scss'],
},
},
],
},
{
test: /\.(woff|woff2|eot|tff|otf)$/,
use: ['file-loader'],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new StyleLintPlugin({
emitErrors: env.prod,
}),
],
};
};