-
Notifications
You must be signed in to change notification settings - Fork 95
/
webpack.web.js
74 lines (69 loc) · 2.16 KB
/
webpack.web.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
/* eslint import/no-extraneous-dependencies: off */
const webpack = require("webpack");
const path = require("path");
const merge = require("webpack-merge");
const { exec } = require("child_process");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const GenerateAssetWebpackPlugin = require("generate-asset-webpack-plugin");
const packageMeta = require("./package.json");
const common = require("./webpack.common.js");
module.exports = merge(common.webpackConfig, {
entry: {
index: "./src/web/index"
},
devServer: {
hot: true,
contentBase: path.join(__dirname, "build/web"),
host: common.siteHost,
port: common.sitePort
},
output: {
path: path.resolve(__dirname, "build/web"),
chunkFilename: "[name].chunk.js",
filename: "[name].js"
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new GenerateAssetWebpackPlugin({
filename: "__version__",
fn: buildVersionJSON
}),
new HtmlWebpackPlugin({
template: "./src/web/index.html.ejs",
filename: "index.html",
chunks: ["index"],
ogImage: `${common.siteUrl}images/color-fb.jpg`,
twitterImage: `${common.siteUrl}images/color-twitter.jpg`,
title: packageMeta.title,
description: packageMeta.description,
homepage: common.siteUrl
}),
new CopyWebpackPlugin({
patterns: [
{ from: "./src/web/testing.html", to: "testing.html" },
{ from: "./src/web/robots.txt", to: "robots.txt" },
{ from: "./src/web/favicon.ico", to: "favicon.ico" },
{ from: "./src/images", to: "images" },
// FIXME: Bundling this in webpack causes it to fail, just copy for now
{ from: "./node_modules/json-url/dist/browser", to: "vendor" }
]
})
]
});
function buildVersionJSON(compilation, cb) {
exec('git --no-pager log --format=format:"%H" -1', (err, stdout, stderr) => {
cb(
null,
JSON.stringify(
{
commit: err ? "" : stdout,
version: packageMeta.version,
source: `https://github.com/${packageMeta.repository}`
},
null,
" "
)
);
});
}