-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
68 lines (65 loc) · 2.47 KB
/
webpack.config.ts
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
/**
* Created by kenkeller on 4/13/17.
*/
import * as fs from "fs";
import * as path from "path";
import * as _ from "lodash";
import * as CommonsChunkPlugin from "webpack/lib/optimize/CommonsChunkPlugin";
export = {
entry: "./app/app.js",
output: {
path: path.join(__dirname, "/public/js"),
filename: '[name].[chunkhash].js',
libraryTarget: 'var',
library: 'h4sApp'
},
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: 'style-loader'},
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
},
plugins: [
new CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
//CommonChunksPlugin will now extract all the common modules from vendor and main bundles
new CommonsChunkPlugin({
name: 'manifest' //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
}),
function() {
this.plugin("done", function(stats) {
const statsAsObj = stats.toJson();
const manifestJS = _.get(statsAsObj, "assetsByChunkName.manifest");
const vendorJS = _.get(statsAsObj, "assetsByChunkName.vendor");
const mainJS = _.get(statsAsObj, "assetsByChunkName.main");
_.forEach(["index", "act"], (f) => {
const template = fs.readFileSync(path.join(__dirname, "template", `${f}.html`)).toString();
const compiledTemplate = _.template(template);
fs.writeFileSync(path.join(__dirname, "public", `${f}.html`), compiledTemplate({
'mainJS': 'js/' + mainJS,
'webpackManifestJS': 'js/' + manifestJS,
'vendorLibsJS': 'js/' + vendorJS
}))
}
);
const json = JSON.stringify(statsAsObj);
fs.writeFileSync(path.join(__dirname, "webpack-stats.json"), json);
});
}
]
};