-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
executable file
·167 lines (162 loc) · 4.78 KB
/
webpack.config.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'use strict';
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const pathsToClean = [
'build'
];
const cleanOptions = {
verbose: true,
dry: false
};
const extractSass = new ExtractTextPlugin({
filename: '[name].[contenthash].css',
publicPath: '/'
});
module.exports = {
// Don't attempt to continue if there are any errors.
bail: true,
context: __dirname,
devtool: 'cheap-module-source-map',
entry: {
main: path.resolve(__dirname, 'app/js/App.js')
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'js/[name].js?[hash:8]',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.jsx', '.scss', '.css']
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'eslint-loader'
},
// ** ADDING/UPDATING LOADERS **
// The "file" loader handles all assets unless explicitly excluded.
// The `exclude` list *must* be updated with every change to loader extensions.
// When adding a new loader, you must add its `test`
// as a new entry in the `exclude` list for "file" loader.
// "file" loader makes sure those assets get served by WebpackDevServer.
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
{
exclude: [
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.(scss|sass)$/,
/\.json$/,
/\.bmp$/,
/\.gif$/,
/\.jpe?g$/,
/\.png$/
],
loader: require.resolve('file-loader'),
options: {
name: '[path][name].[ext]?[hash]'
}
},
// "url" loader works like "file" loader except that it embeds assets
// smaller than specified limit in bytes as data URLs to avoid requests.
// A missing `test` is equivalent to a match.
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: '[path][name].[ext]?[hash]'
}
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: require.resolve('babel-loader')
},
{
test: /\.scss$/,
exclude: /(node_modules|bower_components)/,
use: extractSass.extract({
use: [{
loader: require.resolve('css-loader'),
options: {
importLoaders: 1,
minimize: true,
sourceMap: true
}
}, {
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9' // React doesn't support IE8 anyway
],
flexbox: 'no-2009'
})
],
sourceMap: true
}
}, {
loader: require.resolve('sass-loader'),
options: {
sourceMap: true
}
}
// , {
// loader: require.resolve('sasslint-loader')
// }
],
// use style-loader in development
fallback: 'style-loader'
})
}
]
},
devServer: {
// WebpackDevServer is noisy by default so we emit custom message instead
// by listening to the compiler events with `compiler.plugin` calls above.
contentBase: path.join(__dirname, 'build'),
compress: true,
port: 9000,
// quiet: true,
// Reportedly, this avoids CPU overload on some systems.
// https://github.com/facebookincubator/create-react-app/issues/293
watchOptions: {
ignored: /node_modules/,
},
// Enable HTTPS if the HTTPS environment variable is set to 'true'
// https: protocol === 'https',
historyApiFallback: true,
hot: true
},
plugins: [
new HtmlWebpackPlugin({
template: './app/index.html'
}),
new webpack.HotModuleReplacementPlugin(),
new CopyWebpackPlugin([
{
context: __dirname,
from: 'app/img/**/*',
to: 'build/'
}
]),
extractSass,
new CleanWebpackPlugin(pathsToClean, cleanOptions)
]
};