-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (98 loc) · 2.55 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
const path = require('path');
const webpack = require('webpack');
const dartSass = require('sass');
const manifestFx = require('./manifest.json')
const manifestGc = require('./manifest.chrome.json')
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ZipPlugin = require('zip-webpack-plugin');
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'development';
}
if (process.env.BROWSER != 'chrome') {
process.env.BROWSER = 'firefox';
}
const BROWSER = process.env.BROWSER;
const ENV = process.env.NODE_ENV;
const identity = e => e;
const compact = arr => arr.filter(identity);
const plugins = [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(ENV),
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: compact([
{
from: `manifest${BROWSER == 'firefox' ? '' : `.${BROWSER}`}.json`,
to: "manifest.json" },
"./options/options.html",
BROWSER == 'chrome' ? './offscreen.html' : null,
{ from: "./_locales", to: "_locales" },
{ from: "./icons", to: "icons" },
]),
}),
new MiniCssExtractPlugin(),
];
if (ENV == 'production') {
plugins.push(
new ZipPlugin({
path: path.resolve(__dirname, 'dist'),
filename: `noise-${BROWSER}-${BROWSER == 'firefox' ? manifestFx.version : manifestGc.version}.zip`,
fileOptions: {
mtime: new Date(),
mode: 0o100664,
}
})
);
}
const entries = Object.fromEntries(compact([
['content', './content.js'],
['options', './options/index.js'],
(BROWSER == 'chrome'
? ['offscreen', './offscreen.js']
: null)
]));
if (BROWSER != 'chrome') {
entries['background'] = './background.js';
} else {
entries['background.worker'] = './background.worker.js';
}
module.exports = {
mode: ENV,
entry: entries,
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
},
optimization: {
minimize: false,
},
devtool: ENV == 'development' ? 'source-map' : false,
resolve: {
alias: {
"webextension-polyfill": "webextension-polyfill/dist/browser-polyfill.min.js"
}
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
"css-loader",
{
loader: "sass-loader",
options: {
implementation: dartSass,
},
},
],
},
]
},
plugins: plugins,
}