forked from naver/billboard.js
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
91 lines (83 loc) · 1.83 KB
/
webpack.config.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
82
83
84
85
86
87
88
89
90
91
const pkg = require("./package.json");
const path = require("path");
const webpack = require("webpack");
const StringReplacePlugin = require("string-replace-webpack-plugin");
const Stylish = require("webpack-stylish");
const WebpackMonitor = require("webpack-monitor");
const WebpackBar = require("webpackbar");
const config = {
entry: {
billboard: "./src/core.js"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
libraryTarget: "umd",
umdNamedDefine: true,
},
externals: (context, request, callback) => {
// every 'd3-*' import, will be externally required as their name except root as 'd3'
if (/^d3-/.test(request)) {
return callback(null, {
commonjs: request,
commonjs2: request,
amd: request,
root: "d3"
});
}
callback();
},
devtool: "cheap-module-source-map",
module: {
rules: [
{
test: /(\.js)$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
},
},
{
test: /(\.js)$/,
loader: StringReplacePlugin.replace({
replacements: [{
pattern: /#__VERSION__#/ig,
replacement: () => pkg.version
}]
})
}
]
},
plugins: [
new StringReplacePlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new Stylish(),
new WebpackBar()
],
stats: "minimal",
mode: "none",
devServer: {
// https://github.com/webpack/webpack-dev-server/issues/1604
disableHostCheck: true
}
};
module.exports = () => {
const env = process.env;
let mode = "development";
if (env.NODE_ENV) {
mode = env.NODE_ENV;
}
env.MONITOR && config.plugins.push(
new WebpackMonitor({
launch: true
})
);
if (env.NIGHTLY) {
pkg.version = env.NIGHTLY;
}
mode === "packaged" && delete config.externals;
return require(`./config/webpack.config.${mode}.js`)(config);
};