-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
webpack.config.js
executable file
·135 lines (125 loc) · 3.5 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const path = require('node:path');
const webpack = require('webpack');
const {VueLoaderPlugin} = require('vue-loader');
const {VuetifyPlugin} = require('webpack-plugin-vuetify');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const appVersion = require('./package.json').version;
const storageRevisions = require('./src/storage/config.json').revisions;
const targetEnv = process.env.TARGET_ENV || 'chrome';
const isProduction = process.env.NODE_ENV === 'production';
const enableContributions =
(process.env.ENABLE_CONTRIBUTIONS || 'true') === 'true';
const mv3 = ['chrome'].includes(targetEnv);
const provideExtApi = !['firefox', 'safari'].includes(targetEnv);
const provideModules = {Buffer: ['buffer', 'Buffer']};
if (provideExtApi) {
provideModules.browser = 'webextension-polyfill';
}
const plugins = [
new webpack.DefinePlugin({
'process.env': {
TARGET_ENV: JSON.stringify(targetEnv),
STORAGE_REVISION_LOCAL: JSON.stringify(storageRevisions.local.at(-1)),
STORAGE_REVISION_SESSION: JSON.stringify(storageRevisions.session.at(-1)),
ENABLE_CONTRIBUTIONS: JSON.stringify(enableContributions.toString()),
APP_VERSION: JSON.stringify(appVersion),
MV3: JSON.stringify(mv3.toString())
},
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
}),
new webpack.ProvidePlugin(provideModules),
new VueLoaderPlugin(),
new VuetifyPlugin(),
new MiniCssExtractPlugin({
filename: '[name]/style.css',
ignoreOrder: true
})
];
const entries = {};
if (enableContributions) {
entries.contribute = './src/contribute/main.js';
}
module.exports = {
mode: isProduction ? 'production' : 'development',
entry: {
background: './src/background/main.js',
options: './src/options/main.js',
action: './src/action/main.js',
...entries
},
output: {
path: path.resolve(__dirname, 'dist', targetEnv, 'src'),
filename: '[name]/script.js',
chunkFilename: '[name]/script.js',
asyncChunks: false
},
optimization: {
splitChunks: {
cacheGroups: {
default: false,
commonsUi: {
name: 'commons-ui',
chunks: chunk => {
return ['options', 'action', 'contribute'].includes(chunk.name);
},
minChunks: 2
}
}
}
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
resolve: {
fullySpecified: false
}
},
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
options: {
transformAssetUrls: {img: ''},
compilerOptions: {whitespace: 'preserve'}
}
}
]
},
{
test: /\.(c|sc|sa)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
sassOptions: {
includePaths: ['node_modules'],
quietDeps: true
},
additionalData: (content, loaderContext) => {
return `
$target-env: "${targetEnv}";
${content}
`;
}
}
}
]
}
]
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.json', '.css', '.scss', '.vue'],
fallback: {fs: false}
},
devtool: false,
plugins
};