-
Notifications
You must be signed in to change notification settings - Fork 79
/
webpack.config.js
84 lines (82 loc) · 2.11 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
const path = require("path");
const fs = require("fs");
const TerserPlugin = require("terser-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const examples = fs.readdirSync(
path.resolve(__dirname, "public/example_templates"),
);
const templates = examples.map(
(example) =>
new HtmlWebpackPlugin({
filename: `examples/${example}`,
inject: "head",
scriptLoading: "blocking",
template: path.resolve(__dirname, `public/example_templates/${example}`),
}),
);
const minimizer = [
new TerserPlugin({
extractComments: false,
}),
];
module.exports = (env, argv) => ({
entry: "./src/js/netjsongraph.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "netjsongraph.min.js",
},
devtool: argv.mode === "development" ? "eval-source-map" : "source-map",
optimization: {
minimize: true,
minimizer: argv.mode === "production" ? minimizer : [],
},
module: {
rules: [
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
devServer: {
static: {
directory: path.join(__dirname, "/"),
},
historyApiFallback: true,
open: ["./index.html"],
hot: true,
},
plugins: [
...templates,
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "public/assets"),
to: path.resolve(__dirname, "dist/assets"),
},
{
from: path.resolve(__dirname, "lib"),
to: path.resolve(__dirname, "dist/lib"),
},
{
from: path.resolve(__dirname, "src/css"),
to: path.resolve(__dirname, "dist/lib/css"),
},
{
from: path.resolve(__dirname, "src/js/netjsonWorker.js"),
to: path.resolve(__dirname, "dist/lib/js/netjsonWorker.js"),
},
{
from: path.resolve(__dirname, "index.html"),
to: path.resolve(__dirname, "dist"),
},
],
}),
new Dotenv({systemvars: true}),
],
performance: {
hints: false,
},
});