-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
62 lines (55 loc) · 1.47 KB
/
gatsby-node.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
/* eslint-env node */
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const WorkerPlugin = require('worker-plugin')
exports.onCreateWebpackConfig = ({ actions, getConfig, plugins }) => {
const config = getConfig()
const libPath = path.resolve(__dirname, 'lib')
config.module.rules = [
{
oneOf: [
// Make sure we use this rule for files in `lib`
{
test: /\.js$/,
include: [libPath],
type: 'javascript/auto',
},
{
// Emscripten modules don't work with Webpack's Wasm loader.
test: /\.wasm$/,
exclude: /_bg\.wasm$/,
// This is needed to make webpack NOT process wasm files.
// See https://github.com/webpack/webpack/issues/6725
type: 'javascript/auto',
loader: 'file-loader',
options: {
name: '[name].[hash:5].[ext]',
},
},
{
test: /\.mem$/,
loader: 'file-loader',
options: {
name: '[name].[hash:5].[ext]',
},
},
{
rules: config.module.rules,
},
],
},
]
config.plugins = [
...config.plugins,
new WorkerPlugin({
globalObject: 'self',
}),
]
if (config.optimization) {
config.optimization.minimizer = [
plugins.minifyJs({ test: /(!lib\/.*)/ }),
...config.optimization.minimizer,
]
}
actions.replaceWebpackConfig(config)
}