-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
54 lines (51 loc) · 1.88 KB
/
Copy pathwebpack.config.js
File metadata and controls
54 lines (51 loc) · 1.88 KB
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
const webpack = require('webpack');
const path = require('path');
const WriteFilePlugin = require('write-file-webpack-plugin');
const fs = require('fs');
const csso = require('csso');
// editing index.template.html file
// to do a cache buster for bundle.js as bundle.js is cached by service worker
// this cache buster is detected by service worker and it replaces bundle.js in cahce
fs.readFile('./public/index.template.html', function (err, data) {
if (err) return console.log('Unable to read index.template file', err);
// cache buster:
fs.writeFile('./public/index.template.html',
data.toString('utf8').replace(/bundle\.js.*"/g, "bundle\.js\?v=" + Math.floor(Date.now() / 1000) + "\"")
.replace(/css\/global.*?"/g, 'css\/global.min.css"'),
(err) => {
if (err) console.log("Unable to write to index.template.html", err);
});
});
// minify css:
fs.readFile('./public/css/global.css', function (err, data) {
if (err) return console.log('Unable to read global.css', err);
fs.writeFile('./public/css/global.min.css',
csso.minify(data.toString('utf8'), { restructure: false }).css,
(err) => {
if (err) console.log("Unable to write to global.min.css", err);
});
});
module.exports = {
entry: [
path.join(__dirname, 'src', 'shared', 'client.js')
],
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
loaders: [{
test: path.join(__dirname, 'src'),
exclude: /node_modules/,
loader: ['babel-loader?presets[]=es2015,presets[]=react']
}]
},
plugins: [
new WriteFilePlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
]
};