-
Notifications
You must be signed in to change notification settings - Fork 9
/
gatsby-node.js
34 lines (32 loc) · 1015 Bytes
/
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
const { Transformer } = require('markmap-lib');
const { escapeScript, buildCode } = require('markmap-common');
const viewVersion = require('markmap-view/package.json').version;
const transformer = new Transformer();
const { scripts, styles } = transformer.getAssets();
const assets = {
scripts: scripts?.map(item => {
if (item.type === 'script') return item;
const { fn, getParams } = item.data;
const code = escapeScript(buildCode(fn, getParams?.({
getMarkmap: () => window.markmap,
}) || []));
return {
type: 'script',
data: {
textContent: code,
},
};
}),
styles,
};
exports.onCreateWebpackConfig = async ({ actions, plugins }, pluginOptions) => {
const mergedAssets = (pluginOptions?.assets || (i => i))(assets);
actions.setWebpackConfig({
plugins: [
plugins.define({
'process.env.MARKMAP_ASSETS': JSON.stringify(mergedAssets),
'process.env.MARKMAP_VIEW_VERSION': JSON.stringify(viewVersion),
}),
],
})
};