-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwebpack.config.js
130 lines (113 loc) · 3.34 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const packagejson = require("./package.json");
const dashLibraryName = packagejson.name
.replace(/[-/]/g, "_")
.replace(/@/g, "");
module.exports = (env, argv) => {
const overrides = module.exports || {};
// Mode
let mode;
if (argv && argv.mode) {
mode = argv.mode;
} else if (overrides.mode) {
mode = overrides.mode;
} else {
mode = "production";
}
// Entry
const entry =
argv && argv.entry
? argv.entry[0]
: path.join(__dirname, "src/demo/index.tsx");
// Output
const demo = entry !== "./dist/index.js";
const filenameJs = demo
? "output.js"
: `${dashLibraryName}.${mode === "development" ? "dev" : "min"}.js`;
const filenameCss = demo ? "output.css" : `${dashLibraryName}.css`;
// Devtool
const devtool =
argv.devtool ||
(mode === "development" ? "eval-source-map" : "source-map");
// Externals
const externals = demo
? undefined
: {
react: "React",
"react-dom": "ReactDOM",
"plotly.js": "Plotly",
};
// NOTE: Keep order of the following configuration output
// See: https://webpack.js.org/configuration/
return {
mode,
entry,
target: "web",
output: {
path: demo
? __dirname
: path.resolve(__dirname, "..", dashLibraryName),
filename: filenameJs,
library: dashLibraryName,
libraryTarget: "umd",
},
module: {
rules: [
{
test: /\.(t|j)sx?$/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
},
},
],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
{
loader:
mode === "production"
? MiniCssExtractPlugin.loader
: "style-loader",
},
"css-loader",
],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
use: {
loader: "url-loader",
},
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
devtool: devtool,
externals: externals,
plugins: [
new MiniCssExtractPlugin({
filename: filenameCss,
}),
],
optimization: {
minimizer: [
() => {
return () => {
return {
terserOptions: {},
};
};
},
new CssMinimizerPlugin({}),
],
},
};
};