-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
65 lines (59 loc) · 1.98 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
63
64
65
const path = require('path')
const webpack = require('webpack')
exports.onCreateWebpackConfig = ({ stage, actions, getConfig, plugins }) => {
// console.log('stage', stage)
// console.log('actions', actions)
// console.log('getConfig', getConfig)
// https://webpack.js.org/configuration/resolve/
actions.setWebpackConfig({
resolve: {
fallback: {
fs: false,
path: require.resolve('path-browserify'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer'),
http: require.resolve('stream-http'),
zlib: require.resolve('browserify-zlib'),
https: require.resolve('https-browserify'),
process: require.resolve('process/browser'),
assert: require.resolve('assert')
},
alias: {
react: path.resolve('./node_modules/react'),
'react-dom': path.resolve('./node_modules/react-dom'),
process: 'process/browser'
}
}
})
// Ignore css order
if (stage === 'build-javascript' || stage === 'develop') {
const config = getConfig()
const miniCssExtractPlugin = config.plugins.find(
plugin => plugin.constructor.name === 'MiniCssExtractPlugin'
)
if (miniCssExtractPlugin) {
miniCssExtractPlugin.options.ignoreOrder = true
}
// Create new webpack plugins for resolve 'process/browser'
// and buffer/Buffer
const processPlugin = new webpack.ProvidePlugin({
process: 'process/browser'
})
const bufferPlugin = new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
// Add plugins to webpack plugins array
config.plugins.push(processPlugin)
config.plugins.push(bufferPlugin)
// Save the new config
actions.replaceWebpackConfig(config)
}
}
exports.createPages = async ({ actions }, themeOptions) => {
const basePath = '/'
actions.createPage({
path: basePath,
component: require.resolve('./src/pages/index.js')
})
}