-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.ts
122 lines (111 loc) · 2.65 KB
/
gatsby-node.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import type { GatsbyNode } from 'gatsby'
import type { Configuration } from 'webpack'
import * as path from 'path'
import { promises as fs } from 'fs'
import { LicenseWebpackPlugin } from 'license-webpack-plugin'
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
export const onCreateWebpackConfig: GatsbyNode['onCreateWebpackConfig'] = ({
stage,
plugins,
getConfig,
actions: {
setWebpackConfig,
replaceWebpackConfig,
},
}) => {
setWebpackConfig({
module: {
rules: [
{
test: /\.yml$/u,
include: path.resolve('translations/'),
use: [
{ loader: 'yaml-flat-loader' },
],
},
],
},
plugins: [
new LicenseWebpackPlugin({
perChunkOutput: false,
excludedPackageTest(packageName: string): boolean {
return (/^bundle-optimisations$|^historia-/u).test(packageName)
},
}),
],
resolve: {
plugins: [
new TsconfigPathsPlugin(),
],
},
})
if (stage === 'build-javascript') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const config: Configuration = getConfig()
if (config.optimization) {
config.optimization.minimizer = [
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
plugins.minifyJs({
extractComments: false,
}),
]
replaceWebpackConfig(config)
}
}
}
export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = async ({
actions: {
createTypes,
},
}) => {
createTypes(await fs.readFile(path.resolve('schema.gql'), { encoding: 'utf-8' }))
}
export const createPages: GatsbyNode['createPages'] = ({
actions: {
createRedirect,
createSlice,
},
}) => {
createRedirect({
fromPath: '/latest',
toPath: '/',
isPermanent: true,
redirectInBrowser: true,
})
createSlice({
id: 'header',
component: path.resolve('src/components/Header/index.tsx'),
})
createSlice({
id: 'navbar',
component: path.resolve('src/components/Navbar/index.tsx'),
})
createSlice({
id: 'sidebar',
component: path.resolve('src/components/Sidebar/index.tsx'),
})
createSlice({
id: 'footer',
component: path.resolve('src/components/Footer/index.tsx'),
})
}
export const onCreatePage: GatsbyNode['onCreatePage'] = ({
page,
actions: {
createPage,
deletePage,
},
}) => {
const { dir, name } = path.parse(page.path)
if (page.path === '/') {
return
}
// Force trailing slash for index pages
if (name === 'index') {
deletePage(page)
createPage({
...page,
path: path.join(dir, '/'),
})
}
}