-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
77 lines (71 loc) · 2.08 KB
/
build.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
var webpack = require("webpack");
var path = require("path");
var compile = opt => new Promise((resolve, reject) => webpack(opt, (err, stats) => {
if (err) {
console.error(err);
reject(err);
} else {
process.stdout.write(stats.toString({
colors: true,
chunks: true,
modules: false,
chunkModules: false,
reasons: true,
cached: false,
cachedAssets: false,
}) + "\n");
resolve(stats.toJson());
}
}));
var options = {
entry: {
table: "./src/table.js",
execute: "./src/snippet-execute.js",
index_template: "html?interpolate!./src/index-template.html",
},
output: {
filename: "[name]-[chunkhash].js",
path: "./package",
publicPath: "https://mayorovp.github.io/codegolf/",
},
plugins: [
//new webpack.optimize.UglifyJsPlugin({minimize: true})
new require('copy-webpack-plugin')([
{ from: 'static' },
]),
],
module: {
loaders: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, "src"),
],
loader: 'babel',
query: {
presets: ['es2015'],
},
},
],
},
externals: {
'assetsByChunkName': 'assetsByChunkName',
},
};
compile(options).then(s1 => {
var assetsByChunkName = {};
for (var k in s1.assetsByChunkName)
if (s1.assetsByChunkName.hasOwnProperty(k))
assetsByChunkName[k] = {
localPath: s1.assetsByChunkName[k],
publicPath: options.output.publicPath + s1.assetsByChunkName[k],
};
var fs = require("fs");
try {
var code = fs.readFileSync(options.output.path + "/" + s1.assetsByChunkName.index_template);
var content = require("vm").runInNewContext(`assetsByChunkName => ${code}`)(assetsByChunkName);
fs.writeFileSync(options.output.path + "/index.html", content);
} catch (ex) {
console.error(ex);
}
})