-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgatsby-node.js
61 lines (53 loc) · 1.43 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
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const MonacoWebpackPlugin = require(`monaco-editor-webpack-plugin`);
exports.onCreateWebpackConfig = ({ actions, loaders, stage, getConfig }) => {
const config = getConfig();
if (config.resolve) {
config.resolve.alias = {
...config.resolve.alias,
'@': path.resolve(__dirname, 'src'),
};
} else {
config.resolve = {
alias: { '@': path.resolve(__dirname, 'src') },
};
}
if (!config.plugins) {
config.plugins = [];
}
config.plugins.push(
new MonacoWebpackPlugin({
languages: ['javascript', 'json', 'typescript', 'html'],
})
);
// This will completely replace the webpack config with the modified object.
actions.replaceWebpackConfig(config);
};
exports.createPages = async function ({ actions }) {
const { createPage } = actions;
let meta;
try {
meta = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'src/examples/meta.json'), 'utf8') ||
'{}'
);
} catch (e) {
meta = {};
}
const exampleTemplate = require.resolve('./src/templates/example.tsx');
_.each(meta.demos, demo => {
const source = fs.readFileSync(
`${path.resolve(__dirname, `src/examples/${demo.filename}`)}`,
'utf8'
);
createPage({
path: `/gallery/${demo.pathname}`, // required
component: exampleTemplate,
context: {
source,
},
});
});
};