-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.development.config.js
70 lines (64 loc) · 2.11 KB
/
webpack.development.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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const InterpolateSWPlugin = require('interpolate-sw-plugin');
var env = require('./env.production');
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: path.resolve(__dirname, './docs'),
// Hot Module Replacement complains about using chunkhash, and recommended to use hash instead
filename: '[name].[hash:8].js',
// For dynamic imports (Lazy load). Webpack comment on import call
chunkFilename: '[name].[hash:8].chunk.js',
},
module: {
loaders: [
// Babel loader, depends on babel-preset-react, to be able to load JSX properly.
// Babel preset 'react' must be configured in .babelrc
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
// presets: ['react', 'es2015', 'stage-0']
plugins: ['transform-decorators-legacy']
}
},
// style-loader supports HMR (Hot Module Replacement)
{
test: /\.(s*)css$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
],
},
plugins: [
// Copy the html template and inject the bundles
new HtmlWebpackPlugin({
template: './public/index.html',
minify: {
removeComments: true,
}
}),
// Activates hot module replacement
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new CopyWebpackPlugin([
'./public/manifest.json',
{from: './public/icons/', to: './icons/'},
]),
// Copy the service worker and inject in it the list of assets for pre-cache and cache version
// Notice runing this plugin after CopyWebpackPlugin will include copied files too
new InterpolateSWPlugin({
from: path.resolve(__dirname, './public/sw.js'),
to: 'sw.js',
replaceCacheVersion: true,
replaceAssetFiles: true,
// That would empty the SW file, to deactivate the service worker in DEV mode
deactivateSW: true,
}),
]
};