-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathwebpack.config.js
76 lines (68 loc) · 1.84 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
const path = require('path');
const webpack = require('webpack');
const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
const baseConfig = new ScratchWebpackConfigBuilder(
{
rootPath: path.resolve(__dirname),
enableReact: false,
enableTs: true,
shouldSplitChunks: false
})
.setTarget('browserslist')
.merge({
resolve: {
fallback: {
Buffer: require.resolve('buffer/')
}
}
});
if (!process.env.CI) {
baseConfig.addPlugin(new webpack.ProgressPlugin());
}
// Web-compatible
const webConfig = baseConfig.clone()
.merge({
output: {
library: {
name: 'ScratchStorage',
type: 'umd2'
},
path: path.resolve(__dirname, 'dist', 'web'),
clean: false
}
});
const webNonMinConfig = webConfig.clone()
.merge({
entry: {
'scratch-storage': path.join(__dirname, './src/index.ts')
},
optimization: {
minimize: false
}
});
const webMinConfig = webConfig.clone()
.merge({
entry: {
'scratch-storage.min': path.join(__dirname, './src/index.ts')
},
optimization: {
minimize: true
}
});
// Node-compatible
const nodeConfig = baseConfig.clone()
.merge({
entry: {
'scratch-storage': path.join(__dirname, './src/index.ts')
},
output: {
library: {
type: 'commonjs2'
},
chunkFormat: 'commonjs',
path: path.resolve(__dirname, 'dist', 'node'),
clean: false
}
})
.addExternals(['base64-js', 'js-md5', 'localforage', 'text-encoding']);
module.exports = [webNonMinConfig.get(), webMinConfig.get(), nodeConfig.get()];