forked from naver/billboard.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
100 lines (91 loc) · 2.02 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
92
93
94
95
96
97
98
99
100
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 BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const WebpackBar = require("webpackbar");
const config = {
entry: {
billboard: [
"./src/scss/billboard.scss",
"./src/core.js"
]
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: "this"
},
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: {
test: /node_modules/,
not: [/(d3\-.*)$/]
},
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.ANALYZER && config.plugins.push(
new BundleAnalyzerPlugin()
);
if (env.NIGHTLY) {
pkg.version = env.NIGHTLY;
}
if (env.VERSION) {
pkg.version = env.VERSION;
}
mode === "packaged" && delete config.externals;
return require(`./config/webpack.config.${mode}.js`)(config, env);
};