-
Notifications
You must be signed in to change notification settings - Fork 6
/
gatsby-node.js
96 lines (80 loc) · 2.11 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
92
93
94
95
96
const path = require('path');
const fs = require('fs');
const mkdirp = require('mkdirp');
const Logger = require('./src/lib/logger');
const THEME_NAME = 'fogg';
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
const logger = new Logger(`${THEME_NAME}:onCreateWebpackConfig`);
let themeLocation;
logger.log('Adding theme to Webpack compilation');
try {
themeLocation = require.resolve(THEME_NAME);
} catch (e) {
logger.error(`Failed to load theme module: ${themeLocation}; ${e}`);
return;
}
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.js$/,
include: path.dirname(themeLocation),
use: [loaders.js()]
}
]
}
});
if (stage === 'build-html') {
// This should be a temporary fix in the event gatsby-plugin-react-leaflet removes
// setting react-leaflet as a null loader
const regex = [/node_modules\/leaflet/, /node_modules\\leaflet/];
actions.setWebpackConfig({
module: {
rules: [
{
test: regex,
use: loaders.null()
}
]
}
});
actions.setWebpackConfig({
module: {
rules: [
{
test: /proj4/,
use: loaders.null()
}
]
}
});
actions.setWebpackConfig({
module: {
rules: [
{
test: /esri-leaflet/,
use: loaders.null()
}
]
}
});
}
};
// make sure src/pages exists for the filesystem source or it will error
exports.onPreBootstrap = ({ store }) => {
const logger = new Logger(`${THEME_NAME}:onPreBoostrap`);
const { program } = store.getState();
const dir = `${program.directory}/src/pages`;
logger.log(`Checking if ${dir} exists`);
if (!fs.existsSync(dir)) {
logger.log(`Creating ${dir}`);
mkdirp.sync(dir);
}
};
exports.onCreateBabelConfig = ({ actions }) => {
const logger = new Logger(`${THEME_NAME}:onCreateBabelConfig`);
logger.log('Setting babel preset: @babel/preset-react');
actions.setBabelPreset({
name: 'babel-preset-gatsby'
});
};