Skip to content

Commit

Permalink
fix: avoid loading run-time components at build
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 3, 2020
1 parent df33249 commit babab24
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
]
},
{
"name": "gatsby develop",
"name": "gatsby start",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby",
"cwd": "${workspaceFolder}/examples/gatsby",
"args": ["develop"],
"args": ["start"],
"stopOnEntry": false,
"runtimeArgs": ["--nolazy"],
"sourceMaps": false
Expand Down
3 changes: 2 additions & 1 deletion core/loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"plugin.js",
"loader.js",
"story-store-data.js",
"loader.d.ts"
"loader.d.ts",
"store.js"
],
"scripts": {
"build": "yarn cross-env NODE_ENV=production rollup -c",
Expand Down
1 change: 0 additions & 1 deletion core/loader/src/replaceSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ ${stories
${imports}
${storeConst}
store.config = configJSON;
debugger;
${loadStories}
${hmr}
${exports}
Expand Down
1 change: 1 addition & 0 deletions core/loader/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/store');
2 changes: 1 addition & 1 deletion core/webpack-compile/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const runCompiler = (
console.error(error);
return reject(error);
}
const store = require(path.resolve(__dirname, '../dist', 'bundle.js'));
const { store } = require('@component-controls/loader/store');
resolve({ store, stats });
});
});
Expand Down
7 changes: 6 additions & 1 deletion examples/gatsby/.config/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
stories: [
'../../stories/src/**/*.stories.(js|jsx|tsx|mdx)',
'../../../ui/editors/src/**/*.stories.(js|jsx|tsx|mdx)',
'../../../ui/components/src/**/*.stories.(js|jsx|tsx|mdx)',
'../../../ui/app-components/src/**/*.stories.(js|jsx|tsx|mdx)',
'../../../ui/blocks/src/**/*.stories.(js|jsx|tsx|mdx)',
'../../../core/specification/src/stories/**/*.stories.(js|jsx|tsx|mdx)',
],
'../../../plugins/axe-plugin/src/stories/**/*.stories.(js|jsx|tsx|mdx)',
],
};
13 changes: 5 additions & 8 deletions integrations/gatsby-theme-stories/src/gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
CompileProps,
} from '@component-controls/webpack-compile';
import { NodePluginArgs, NodeInput, CreatePagesArgs } from 'gatsby';
import { StoriesStore } from '@component-controls/specification';
import { loadStoryStore } from '@component-controls/store';
import { LoaderOptions } from './types';

const defaultPresets = ['react', 'react-docgen-typescript'];
Expand All @@ -20,16 +18,15 @@ exports.sourceNodes = async function sourceNodes(
presets: defaultPresets,
configPath: options.configPath,
};
const { store } = false ? await watch(config) : await compile(config);
const loadedStore: StoriesStore | undefined = loadStoryStore(store);
const { store } = true ? await watch(config) : await compile(config);

if (loadedStore) {
Object.keys(loadedStore.docs).forEach(key => {
if (store) {
store.stores.forEach(s => {
//@ts-ignore
const doc = loadedStore.docs[key];
const doc = s.doc;

const docMetadata: NodeInput = {
id: createNodeId(`storyDoc-${key}`),
id: createNodeId(`storyDoc-${doc?.title}`),
children: [],
internal: {
type: 'storyDoc',
Expand Down

0 comments on commit babab24

Please sign in to comment.