-
Notifications
You must be signed in to change notification settings - Fork 8
/
gatsby-node.js
91 lines (88 loc) · 2.58 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* eslint-disable no-console */
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const { createPagesWithData } = require('@edx/gatsby-source-portal-designer/createPagesWithData');
const { templates } = require('./templates');
// **Note:** The graphql function call returns a Promise
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise for more info
exports.createPages = async ({ graphql, actions }) => graphql(`
{
allPage {
nodes {
id
slug
title
type
uuid
hostname
contact_email
program_documents {
header
display
documents {
display_text
document
url
}
}
external_program_website {
header
display
description
link {
display_text
url
}
}
branding {
cover_image
banner_border_color
texture_image
organization_logo {
url
alt
}
}
}
}
}
`)
.then((result) => {
if (result && result.data) {
createPagesWithData(result, actions, templates);
} else {
console.error('GraphQL query for fetching page nodes returned no data.');
}
})
.catch((error) => {
console.error('An error occurred while fetching page nodes from GraphQL', error);
});
exports.onCreateWebpackConfig = ({ actions, loaders, getConfig }) => {
const config = getConfig();
config.module.rules = [
// Omit the default rule where test === '\.jsx?$'
...config.module.rules.filter(rule => String(rule.test) !== String(/\.jsx?$/)),
// Recreate it with custom exclude filter
{
// Called without any arguments, `loaders.js` will return an
// object like:
// {
// options: undefined,
// loader: '/path/to/node_modules/gatsby/dist/utils/babel-loader.js',
// }
// Unless you're replacing Babel with a different transpiler, you probably
// want this so that Gatsby will apply its required Babel
// presets/plugins. This will also merge in your configuration from
// `babel.config.js`.
...loaders.js(),
test: /\.jsx?$/,
// Exclude all node_modules from transpilation, except for 'swiper' and 'dom7'
exclude: modulePath => /node_modules/.test(modulePath),
},
];
// This will completely replace the webpack config with the modified object.
actions.replaceWebpackConfig(config);
};