-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
100 lines (90 loc) · 3.19 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
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const execSync = require('child_process').execSync
const CreateFileWebpack = require('create-file-webpack')
const webpack = new require('webpack')
module.exports = () => {
const mode = process.env.NODE_ENV || 'development'
const SOURCE_FOLDER = path.resolve(__dirname, 'src')
const DIST_FOLDER = path.resolve(__dirname, 'dist')
const LIB_FILE = path.resolve(__dirname + '/node_modules/enq-web3/dist/enqweb3lib.ext.min.js')
const VERSION = execSync('git rev-parse --short HEAD').toString().trim()
const COPY = {
patterns: [
{
from: path.join(SOURCE_FOLDER, 'copied'),
to: DIST_FOLDER
},
{
from: LIB_FILE,
to: path.join(DIST_FOLDER, 'lib'),
}]
}
const plugins = [];
plugins.push(new CopyWebpackPlugin(COPY))
plugins.push(new CreateFileWebpack({
path: './dist/',
fileName: 'VERSION',
content: VERSION
}))
// plugins.push(new webpack.EnvironmentPlugin(['VERSION']))
plugins.push(new webpack.DefinePlugin({
VERSION: JSON.stringify(VERSION),
process: 'process',
}))
plugins.push(new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}))
// new webpack.DefinePlugin({
//
// })
return {
mode,
entry: {
popup: path.resolve(SOURCE_FOLDER, 'popup.js'),
background: path.resolve(SOURCE_FOLDER, 'background.js'),
contentScript: path.resolve(SOURCE_FOLDER, 'contentScript.js'),
lockAccount: path.resolve(SOURCE_FOLDER, 'lockAccount.js'),
'../serviceWorker': path.resolve(SOURCE_FOLDER, 'serviceWorker.ts'),
serviceWorkerRegistration: path.resolve(SOURCE_FOLDER, 'serviceWorkerRegistration.ts'),
workerDataParse: path.resolve(SOURCE_FOLDER, './utils/workerDataParse.js'),
WebWorkerPOA: path.resolve(SOURCE_FOLDER, './utils/poa/WebWorkerPOA.js'),
},
output: {
filename: 'js/[name].js',
path: DIST_FOLDER,
publicPath: './'
},
devtool: 'inline-source-map',
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".styl", ".css", ".png", ".jpg", ".icns", ".gif", ".svg", ".woff", ".woff2", ".ttf", ".otf"],
fallback: {
"stream": require.resolve("stream-browserify"),
"buffer": require.resolve("buffer")
},
alias: {
"buffer": "buffer",
"stream": "stream-browserify"
}
},
plugins,
module: {
rules: [
{
test: /\.(jsx?)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
}
}