forked from deriv-com/sinbad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
70 lines (61 loc) · 1.92 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
66
67
68
69
70
/* eslint-disable import/order */
const path = require('path')
// const positions = require('src/pages/job-description/data')
exports.onCreatePage = () => {}
const StylelintPlugin = require('stylelint-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const style_lint_options = {
files: 'src/**/*.js',
emitErrors: false,
lintDirtyModulesOnly: true,
}
exports.onCreateWebpackConfig = ({ actions, getConfig }, { ...options }) => {
const config = getConfig()
if (config.optimization) {
config.optimization.minimizer = [new TerserPlugin()]
}
actions.setWebpackConfig({
plugins: [new StylelintPlugin({ ...style_lint_options, ...options })],
resolve: {
alias: {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
'react/jsx-runtime': 'preact/jsx-runtime',
},
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
})
}
exports.createPages = async ({ reporter, actions, graphql }) => {
const { createPage } = actions
const position_template = path.resolve(__dirname, 'src/templates/position.tsx')
// Fetch the data JSON for positions
const result = await graphql(`
query All {
allPositionsJson {
edges {
node {
slug
}
}
}
}
`)
if (result.errors) {
reporter.panic(result.errors)
}
const positions = result.data.allPositionsJson.edges
positions.forEach(({ node: { slug } }) => {
const path = `/job-description/${slug}/`
createPage({
path,
component: position_template,
context: {
locale: 'en',
pathname: path,
slug,
},
})
})
}