-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (110 loc) · 3.08 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
const webpack = require('webpack')
const path = require('path')
const TerserWebpackPlugin = require('terser-webpack-plugin')
function defineConfig (mode, entryName) {
/** @type {import('webpack').Configuration} */
const config = {
mode,
target: ['es5', 'web'],
entry: {
[entryName]: path.join(__dirname, './src/index.js')
},
node: {
global: true
},
output: {
filename: '[name].js',
path: path.join(__dirname, './dist'),
library: 'memfs',
libraryTarget: 'umd',
globalObject: '(typeof globalThis !== "undefined" ? globalThis : (typeof window !== "undefined" ? window : this)) || self'
},
resolve: {
alias: {
buffer: path.join(__dirname, './src/buffer.js'),
},
fallback: {
process: require.resolve('process/browser'),
assert: path.join(__dirname, './src/assert.js'),
url: path.join(__dirname, './src/url.js'),
// buffer: path.join(__dirname, './src/buffer.js'),
util: require.resolve('util/'),
path: require.resolve('path-browserify'),
stream: require.resolve('readable-stream'),
events: require.resolve('events/'),
// punycode: require.resolve('punycode/'),
// querystring: require.resolve('querystring/'),
string_decoder: require.resolve('string_decoder/')
}
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_DEBUG': 'false',
'__MEMFS_BROWSER_VERSION__': JSON.stringify(require('./package.json').version),
'__MEMFS_BROWSER_ORIGINAL_VERSION__': JSON.stringify(require('./package.json').dependencies.memfs)
}),
new webpack.ProvidePlugin({
process: require.resolve('process/browser'),
Buffer: ['buffer', 'Buffer']
})
],
optimization: {
minimizer: [
new TerserWebpackPlugin({
parallel: true,
extractComments: false,
terserOptions: {
output: {
comments: false,
beautify: false
}
}
})
]
}
}
return config
}
function defineBufferConfig (mode) {
/** @type {import('webpack').Configuration} */
const config = {
mode,
target: ['es5', 'web'],
entry: {
buffer: path.join(__dirname, './test/buffer-entry.js')
},
node: {
global: true
},
output: {
filename: '[name].js',
path: path.join(__dirname, './test'),
library: {
// export: ['Buffer'],
type: 'umd',
name: 'buffer'
},
globalObject: '(typeof globalThis !== "undefined" ? globalThis : (typeof window !== "undefined" ? window : this)) || self'
},
optimization: {
minimizer: [
new TerserWebpackPlugin({
parallel: true,
extractComments: false,
terserOptions: {
output: {
comments: false,
beautify: false
}
}
})
]
}
}
return config
}
module.exports = [
defineConfig('none', 'memfs'),
defineConfig('production', 'memfs.min'),
defineBufferConfig('none')
]