-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
103 lines (95 loc) · 2.17 KB
/
webpack.config.js
File metadata and controls
103 lines (95 loc) · 2.17 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv');
const {merge} = require('webpack-merge');
const TerserPlugin = require('terser-webpack-plugin');
dotenv.config();
const extensionPath = path.join(__dirname, 'src');
const commonConfig = {
entry: {
extension: {
import: path.join(extensionPath, 'background.ts'),
filename: 'background.js',
},
configure: {
import: path.join(extensionPath, 'action/index.tsx'),
filename: 'action.js',
},
superappWidget: {
import: path.join(extensionPath, 'content-script/index.tsx'),
filename: 'contentScript.js',
},
},
output: {
clean: true,
filename: '[name].js',
path: path.resolve('.', 'dist'),
},
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [
{
loader: 'style-loader',
options: {
injectType: 'lazyStyleTag',
insert: function insertIntoTarget(element, options) {
// eslint-disable-next-line
const parent = options.target || document.head;
parent.appendChild(element);
},
},
},
// 'style-loader',
'css-loader',
'sass-loader',
],
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(png|gif|jpg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [new webpack.EnvironmentPlugin([])],
};
const devConfig = {
mode: 'development',
devtool: 'cheap-module-source-map',
};
const prodConfig = {
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: true,
},
}),
],
},
};
let config = {};
if (process.env.NODE_ENV === 'production') {
config = merge(commonConfig, prodConfig);
} else {
config = merge(commonConfig, devConfig);
}
module.exports = config;