-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
149 lines (144 loc) · 4.11 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const CopyPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const YamlLocalesWebpackPlugin = require('yaml-locales-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const WebpackExtensionManifestPlugin = require('webpack-extension-manifest-plugin');
const { merge } = require('webpack-merge');
const resolve = require('path').resolve;
const webpack = require('webpack');
const dotEnv = new Dotenv();
const manifestBase = require('./src/manifest/base.json');
const manifestChrome = require('./src/manifest/chrome.json');
const manifestFireFox = require('./src/manifest/firefox.json');
const pkg = require('./package.json');
module.exports = (env, argv) => {
let manifestConfig = {
base: manifestBase,
extend: { version: pkg.version },
};
if (argv.firefox) {
const extID = dotEnv.definitions['process.env.FF_EXT_ID'].replace(/"/g, '');
manifestConfig.extend = { ...manifestConfig.extend, ...manifestFireFox };
manifestConfig.extend.browser_specific_settings.gecko.id = `{${extID}}`;
} else {
manifestConfig.extend = { ...manifestConfig.extend, ...manifestChrome };
if (argv.mode !== 'production') {
manifestConfig.extend.key = dotEnv.definitions[
'process.env.EXTENSION_KEY'
].replace(/"/g, '');
}
}
const config = {
entry: {
background: './src/background.js',
popup: './src/popup/popup.js',
options: './src/options/options.js',
log: './src/log/log.js',
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
extensions: ['.js', '.vue', '.json'],
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
},
},
],
},
],
},
plugins: [
new Dotenv(),
new HtmlWebpackPlugin({
filename: 'popup.html',
template: 'src/popup/popup.html',
chunks: ['popup'],
}),
new HtmlWebpackPlugin({
filename: 'options.html',
template: 'src/options/options.html',
chunks: ['options'],
}),
new HtmlWebpackPlugin({
filename: 'log.html',
template: 'src/log/log.html',
chunks: ['log'],
}),
new CopyPlugin({
patterns: [
{ from: 'src/icons', to: 'icons' },
{ from: 'src/assets', to: 'assets' },
],
}),
new WebpackExtensionManifestPlugin({
config: manifestConfig,
}),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new YamlLocalesWebpackPlugin({
messageAdditions: argv.beta
? { extName: ' (beta)', BrowserActionTitle: ' (beta)' }
: {},
}),
new VueLoaderPlugin(),
new webpack.ProgressPlugin(),
],
};
if (argv.mode === 'production') {
return merge(
{
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
output: {
comments: false,
},
},
extractComments: false,
}),
new OptimizeCSSAssetsPlugin({}),
],
},
},
config
);
} else {
// development mode
return merge(config, {
devtool: 'inline-source-map',
});
}
};