-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
62 lines (57 loc) · 2.1 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions
const newPage = Object.assign({}, page)
// Duplicate page for english
// if (page.path === "/asia/" || page.path === "/asia/vietnam/southern-vietnam/discover/") {
newPage.path = "en" + page.path
createPage(page)
createPage(newPage)
// }
}
exports.onCreateWebpackConfig = ({ stage, actions, getConfig, plugins }) => {
const PATTERN = /\.(eot|otf|ttf|woff(2)?)(\?.*)?$/
const config = getConfig()
if (stage === "build-javascript" && process.env.CIRCLECI === "true") {
// setting manually the number of parallel in circle ci, because sometimes out of memory happens
// https://github.com/facebook/create-react-app/issues/8320
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/202#issuecomment-580704210
// https://webpack.js.org/plugins/terser-webpack-plugin/#parallel
console.log("DETECTED CIRCLE-CI - SETTING TERSER PARALLEL TO 8")
config.optimization.minimizer[0].options.parallel = 8
} else {
console.log(`DID NOT DETECT CIRCLE-CI => process.env.CIRCLECI=${process.env.CIRCLECI}`)
}
// migration v2 to v3
if (stage === "build-javascript" || stage === "develop") {
config.plugins.push(plugins.provide({ process: "process/browser" }))
}
const newConfig = {
...config,
// migration v2 to v3
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
path: require.resolve("path-browserify"),
},
},
module: {
// Manually swap out the rule who's test matches PATTERN
rules: config.module.rules.map((rule) => {
if (rule.test && rule.test.toString() === PATTERN.toString()) {
rule.use[0].options.limit = 1
rule.use[0].options.name = `static/fonts/[name]-[hash].[ext]`
}
return rule
}),
},
}
actions.replaceWebpackConfig(newConfig)
}