-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.prod.js
52 lines (47 loc) · 1.45 KB
/
webpack.prod.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
/* global require module */
const sourceDir = 'src/client';
const webpack = require('webpack');
const WebpackMerge = require('webpack-merge');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const commonConfig = require('./webpack.common.js');
const packageDetails = require('./package.json');
const configs = require('./configs.json');
const copy = new CopyWebpackPlugin([
{
from: `${sourceDir}/sw.js`,
transform: (content, path) =>
content.toString()
.replace(/#sw-cache-string#/g, (new Date().getTime()))
.replace(/#sw-origin#/g, configs.origin)
},
{
from: `${sourceDir}/manifest.json`,
transform: (content, path) =>
content.toString()
.replace(/#manifest-origin#/g, configs.origin)
}
]);
const html = new HtmlWebpackPlugin({
template: `${sourceDir}/index.ejs`,
templateParameters: {
titlePrefix: '',
baseUrl: `${configs['ssl-cert-path'] ? 'https' : 'http'}://${configs.domain}${configs.origin}`,
version: packageDetails.version
},
filename: 'index.html',
chunks: ['app'],
hash: true
});
module.exports = WebpackMerge(
commonConfig,
{
mode: 'production',
plugins: [
copy,
new UglifyJSPlugin(),
html
]
}
);