-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
webpack.config.js
116 lines (111 loc) · 3.96 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
const { merge } = require("webpack-merge");
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts");
const srcDir = path.join(__dirname, ".", "src");
const commonConfig = {
entry: {
// Typescript Entry Points
popup: path.join(srcDir, "scripts/popup.ts"),
options: path.join(srcDir, "scripts/options.ts"),
background: path.join(srcDir, "scripts/background.ts"),
content: path.join(srcDir, "scripts/content.ts"),
offscreen: path.join(srcDir, "scripts/offscreen.ts"),
"theme-editor": path.join(srcDir, "scripts/theme-editor.ts"),
"default-icons-page": path.join(srcDir, "scripts/default-icons-page.ts"),
// CSS Entry Points
"styles/all": path.join(srcDir, "styles/all.scss"),
"styles/modern/all": path.join(srcDir, "styles/modern/all.scss"),
"styles/theme-editor": path.join(srcDir, "styles/theme-editor.scss"),
"styles/modern/theme-editor": path.join(srcDir, "styles/modern/theme-editor.scss"),
"lib/jquery-ui": path.join(srcDir, "../node_modules/jquery-ui/themes/base/all.css"),
"lib/contextmenu": path.join(
srcDir,
"../node_modules/jquery-contextmenu/dist/jquery.contextMenu.min.css"
),
"lib/izitoast": path.join(srcDir, "../node_modules/izitoast/dist/css/iziToast.min.css"),
"lib/materialize": path.join(
srcDir,
"../node_modules/materialize-css/dist/css/materialize.min.css"
),
"lib/spectrum": path.join(srcDir, "../node_modules/spectrum-colorpicker/spectrum.css"),
},
output: {
filename: "[name].js",
path: path.join(__dirname, "./dist"),
},
externals: {
jquery: "jQuery",
"materialize-css": "M",
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
// Creates `style` nodes from JS strings
// "style-loader",
// Translates CSS into CommonJS (for postcss-loader because it takes css as input)
{
loader: "css-loader",
options: { url: false },
},
// Compiles Sass to CSS
"sass-loader",
],
},
{
test: /\.svg$/,
use: [
{
loader: "svg-inline-loader",
},
],
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: path.resolve("src/static"), to: path.resolve("dist") },
{ from: path.resolve("src/styles"), to: path.resolve("dist/styles") },
{ from: path.resolve("src/html"), to: path.resolve("dist") },
{
from: path.resolve("node_modules/materialize-css/dist/js/materialize.js"),
to: path.resolve("dist/lib"),
},
],
options: {},
}),
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
],
};
const productionConfig = {
mode: "production",
devtool: "inline-source-map",
};
const developmentConfig = {
mode: "development",
devtool: "inline-source-map",
};
module.exports = (_env, argv) => {
if (argv.mode === "production") {
return merge(commonConfig, productionConfig);
}
if (argv.mode === "development") {
return merge(commonConfig, developmentConfig);
}
};