-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
75 lines (71 loc) · 1.8 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
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
function copyStaticAssets(files, folders) {
const staticAssets = [];
const collectAssets = (assets, toType) => {
assets.forEach(asset => {
staticAssets.push({from: `./${asset}`, to: `./${asset}`, toType})
});
}
collectAssets(files, "file");
collectAssets(folders, "dir");
return new CopyWebpackPlugin(staticAssets);
}
module.exports = (env, argv) => {
const devMode = argv.mode !== "production";
const plugins = [
copyStaticAssets(
["manifest.json", ".web-extension-id", "LICENSE.md"],
["img"]
),
new HtmlWebpackPlugin({
template: "./src/templates/popup.html",
filename: "popup.html",
chunks: ["popup"]
}),
new HtmlWebpackPlugin({
template: "./src/templates/options.html",
filename: "options.html",
chunks: ["options"]
})
];
return {
mode: "development",
entry: {
popup: "./src/js/popup.js",
options: "./src/js/options.js"
},
output: {
path: path.resolve(__dirname, "addon"),
filename: "[name].js",
publicPath: "/"
},
devtool: devMode ? "source-map" : false,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
["@babel/preset-env", {modules: false}]
]
}
}
},
{
test: /\.(s*)css$/,
use: ["style-loader", "css-loader", "postcss-loader", "sass-loader"]
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
use: ["file-loader"]
}
]
},
plugins
};
};