-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebpack.config.babel.js
81 lines (75 loc) · 2.52 KB
/
webpack.config.babel.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
77
78
79
80
81
import path from "path";
import webpack from "webpack";
import UglifyJsPlugin from "uglifyjs-webpack-plugin";
import ExtractTextPlugin from "extract-text-webpack-plugin";
import pkg from "./package.json";
function inmodules(...parts) {
return new RegExp("^" + path.join(__dirname, "node_modules", ...parts) + "$");
}
function insrc(...parts) {
return new RegExp("^" + path.join(__dirname, "src", ...parts) + "$");
}
function q(loader, query) {
return loader + "-loader?" + JSON.stringify(query);
}
const DIST_DIR = path.join("dist", "app");
const DEBUG = process.env.NODE_ENV !== "production";
const WIN_BUILD = process.env.PLATFORM === "win32";
const TISTORE_VERSION = `${pkg.name} v${pkg.version} “${pkg.codename}”`;
const NAMEQ = {name: "[name]"};
const FULLNAMEQ = {name: "[name].[ext]"};
const MANIFEST_OPTS = DEBUG ? ',"chromium-args":"--enable-logging=stderr"' : "";
const INDEX_LOADERS = [
q("file", NAMEQ),
q("ejs-html", {title: TISTORE_VERSION}),
];
const PACKAGE_LOADERS = [
q("file", NAMEQ),
q("ejs-html", {opts: MANIFEST_OPTS}),
];
const ExtractLoader = ExtractTextPlugin.extract("css-loader");
const COMMON_PLUGINS = [
new webpack.DefinePlugin({WIN_BUILD}),
new ExtractTextPlugin("index.css"),
];
const PLUGINS = DEBUG ? COMMON_PLUGINS : COMMON_PLUGINS.concat([
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false,
},
},
}),
]);
export default {
target: "node",
stats: {
children: false,
entrypoints: false,
modules: false,
},
entry: "./src/index/index",
output: {
path: path.join(__dirname, DIST_DIR),
filename: "index.js",
},
// XXX(Kagami): Not actually needed and has ES6 deps which is not
// supported by current minify configuration.
externals: [{hawk: "undefined"}],
module: {
// See <https://github.com/webpack/webpack/issues/138>.
noParse: inmodules(".*json-schema", "lib", "validate\\.js"),
loaders: [
{test: /\.json$/, loader: "json-loader"},
{test: /\.(png|exe)$/, loader: "file-loader", query: FULLNAMEQ},
{test: insrc(".+\\.js"), loader: "babel-loader"},
{test: insrc("index", "index\\.html\\.ejs"), loaders: INDEX_LOADERS},
{test: insrc("index", "package\\.json\\.ejs"), loaders: PACKAGE_LOADERS},
// Fonts, font-awesome.
{test: /\.woff2(\?v=[\d.]+)?$/, loader: "file-loader", query: FULLNAMEQ},
{test: /\.(ttf|eot|svg|woff)(\?v=[\d.]+)?$/, loader: "skip-loader"},
{test: inmodules("font-awesome", ".+\\.css"), loader: ExtractLoader},
],
},
plugins: PLUGINS,
};