-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebpack.config.js
More file actions
83 lines (78 loc) · 2.42 KB
/
Copy pathwebpack.config.js
File metadata and controls
83 lines (78 loc) · 2.42 KB
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
const path = require('path');
const TerserPlugin = require("terser-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const ConcatPlugin = require('@mcler/webpack-concat-plugin');
const JsonMinimizerPlugin = require("json-minimizer-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
module.exports = env => ({
/// background script
entry: {
index: "./src/content.js"
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: "[name].js"
},
plugins: [
/// content scripts
new ConcatPlugin({
name: 'content',
outputPath: './',
fileName: '[name].js',
filesToConcat: [
"./src/configs.js",
"./src/content.js",
]
}),
new ConcatPlugin({
name: 'background',
outputPath: './',
fileName: '[name].js',
filesToConcat: [
"./src/configs.js",
"./src/background.js",
]
}),
/// static files
new CopyPlugin({
patterns: [
{ from: "src/content.css", to: "content.css" },
{ from: "src/assets/_locales", to: "_locales" },
{ from: "src/assets/icon_new.png", to: "icon_new.png" },
{ from: "src/options", to: "options" },
{ from: "src/viewer", to: "viewer" },
/// additional dependencies for the options page
{ from: "src/configs.js", to: "configs.js" },
// { from: "src/manifest.json", to: "manifest.json" },
... env.build == 'chrome' ? [
{
from: "src/manifest.json",
to: "manifest.json",
transform(content, absoluteFrom) {
const manifest = JSON.parse(content.toString());
/// Remove background.scripts (from manifest v2)
delete manifest['background']['scripts'];
/// Remove Firefox-specific permissions
const permissionsToRemove = ['contextualIdentities', 'cookies'];
manifest.permissions = manifest.permissions.filter(
permission => !permissionsToRemove.includes(permission)
);
return JSON.stringify(manifest);
},
}
] : [
{ from: "src/manifest.json", to: "manifest.json" }
],
],
}),
],
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin(),
new JsonMinimizerPlugin(),
],
},
});