forked from oasisprotocol/oasis-wallet-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
137 lines (135 loc) · 3.07 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
const webpack = require("webpack");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = (env, argv) => {
console.log('argv.mode', argv.mode)
const mode = argv.mode;
const isDev = mode === 'development';
/** @type {import('webpack').Configuration} */
const config = {
entry: {
background: "./src/background/index.js",
popup: "./src/index.js",
xuframe:"./src/background/service/ExtUtils.js"
},
output: {
path: path.resolve(__dirname, "./dist"),
filename: "./[name].js",
},
module: {
//加载器配置
rules: [
{
test: /\.css$/,
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
options: {
url: false,
sourceMap: true,
},
},
],
},
{
test: /\.js$/, exclude: /node_modules/, loader: "babel-loader",
},
{
test: /\.jsx$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/env", "@babel/react"],
},
},
},
{
test: /\.scss$/,
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
},
{
loader: "sass-loader",
},
],
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [
{
loader: "url-loader",
options: {
limit: 8192,
},
},
],
},
],
},
resolve: {
alias: {
'@protobufjs/inquire': path.resolve(__dirname, "./src/errata/inquire"),
},
},
plugins: getPlugins(isDev),
performance: getPerformance(),
node: {
fs: 'empty',
'child_process': 'empty'
},
optimization: {
splitChunks: {
chunks: "all",
minSize: 4194300,
cacheGroups: {
default: {
name: 'common',
chunks: 'initial',
minChunks: 2,
},
}
}
},
};
if (isDev) {
config.devtool = 'cheap-module-source-map';
config.optimization.minimize = false;
}
return config;
}
function getPerformance() {
return {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
};
}
function getPlugins(isDev) {
let plugins = [];
plugins.push(
new CopyWebpackPlugin({
patterns: [
{ from: "./public/static", to: "./" },
{ from: "./public/manifest.json", to: "./" },
{ from: "./public/oasis-xu-frame.html", to: "./" },
{ from: "./src/_locales", to: "./_locales" },
],
}),
new webpack.ProvidePlugin({
React: "react",
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env.NODE_ENV),
IS_DEV: JSON.stringify(isDev),
}),
);
return plugins;
}