-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
webpack.config.dist.js
125 lines (121 loc) · 3.35 KB
/
webpack.config.dist.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
/* Copyright (c) 2018 Kamil Mikosz
* Copyright (c) 2019 Sienori
* Released under the MIT license.
* see https://opensource.org/licenses/MIT */
const CopyWebpackPlugin = require("copy-webpack-plugin");
const {
getHTMLPlugins,
getOutput,
getCopyPlugins,
getZipPlugin,
getFirefoxCopyPlugins,
getMiniCssExtractPlugin,
getEntry
} = require("./webpack.utils");
const path = require("path");
const config = require("./config.json");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const extVersion = require("./src/manifest-chrome.json").version;
const ffExtVersion = require("./src/manifest-firefox.json").version;
const generalConfig = {
mode: "production",
resolve: {
alias: {
src: path.resolve(__dirname, "src/"),
"webextension-polyfill": "webextension-polyfill/dist/browser-polyfill.min.js"
}
},
module: {
rules: [
{
loader: "babel-loader",
exclude: /node_modules/,
test: /\.(js|jsx)$/,
resolve: {
extensions: [".js", ".jsx"]
}
},
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
esModule: false
}
},
{
loader: "sass-loader"
}
]
},
{
test: /\.svg$/,
use: ["@svgr/webpack"]
}
]
}
};
module.exports = [
{
...generalConfig,
output: getOutput("chrome", config.tempDirectory),
entry: getEntry(config.chromePath),
optimization: {
minimize: true
},
plugins: [
new CleanWebpackPlugin(["dist", "temp"]),
...getMiniCssExtractPlugin(),
...getHTMLPlugins("chrome", config.tempDirectory, config.chromePath),
...getCopyPlugins("chrome", config.tempDirectory, config.chromePath),
getZipPlugin(`${config.extName}-for-chrome-${extVersion}`, config.distDirectory)
]
},
{
...generalConfig,
entry: getEntry(config.firefoxPath),
output: getOutput("firefox", config.tempDirectory),
optimization: {
minimize: true
},
plugins: [
new CleanWebpackPlugin(["dist", "temp"]),
...getMiniCssExtractPlugin(),
...getHTMLPlugins("firefox", config.tempDirectory, config.firefoxPath),
...getFirefoxCopyPlugins("firefox", config.tempDirectory, config.firefoxPath),
getZipPlugin(`${config.extName}-for-firefox-${ffExtVersion}`, config.distDirectory)
]
},
{
mode: "production",
resolve: {
alias: {
src: path.resolve(__dirname, "src/")
}
},
entry: { other: path.resolve(__dirname, `src/background/background.js`) },
output: getOutput("copiedSource", config.tempDirectory),
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: `src`,
to: path.resolve(__dirname, `${config.tempDirectory}/copiedSource/src/`),
info: { minimized: true }
},
{
from: "*",
to: path.resolve(__dirname, `${config.tempDirectory}/copiedSource/`),
globOptions: {
ignore: ["**/BACKERS.md", "**/crowdin.yml"]
}
}
]
}),
getZipPlugin(`copiedSource-${config.extName}-${ffExtVersion}`, config.distDirectory, "other/")
]
}
];