Skip to content

Commit

Permalink
fix: nextjs story bundle location
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 20, 2020
1 parent 8e13d58 commit 636ffac
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 42 deletions.
2 changes: 1 addition & 1 deletion core/webpack-compile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ _defined in [@component-controls/webpack-compile/src/types.ts](https://github.co

| Name | Type | Description |
| -------------- | ------------------------------- | --------------------------------------------------------------------- |
| `bundleName` | string | public file name the bundle, by default 'compoonent-controls.js' |
| `bundleName` | string | public file name the bundle, by default 'component-controls.js' |
| `configPath` | string | path to the configuration file e.g : '.storybook' |
| `distFolder` | string | public output folder for the bundle |
| `presets` | [RuleTypes](#ruletypes) | a list of webpack configuration presets from webpack-configs packages |
Expand Down
2 changes: 1 addition & 1 deletion core/webpack-compile/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface CompileProps {
/** public output folder for the bundle */
distFolder?: string;

/** public file name the bundle, by default 'compoonent-controls.js' */
/** public file name the bundle, by default 'component-controls.js' */
bundleName?: string;

/** public output folder for the assets like images */
Expand Down
2 changes: 1 addition & 1 deletion core/webpack-compile/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type CompileRunProps = CompileProps & {
mode: Configuration['mode'];
};

export const defBundleName = 'compoonent-controls.js';
export const defBundleName = 'component-controls.js';

export const getBundleName = (options: CompileProps) =>
path.join(
Expand Down
7 changes: 0 additions & 7 deletions examples/starter/store.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/store.js

This file was deleted.

2 changes: 1 addition & 1 deletion integrations/nextjs-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ _build [source code](https://github.com/ccontrols/component-controls/tree/master
| `presets` | _RuleTypes_ | a list of webpack configuration presets from webpack-configs packages |
| `configPath` | _string_ | path to the configuration file e.g : '.storybook' |
| `distFolder` | _string_ | public output folder for the bundle |
| `bundleName` | _string_ | public file name the bundle, by default 'compoonent-controls.js' |
| `bundleName` | _string_ | public file name the bundle, by default 'component-controls.js' |
| `staticFolder` | _string_ | public output folder for the assets like images |

## <ins>Layout</ins>
Expand Down
16 changes: 16 additions & 0 deletions integrations/nextjs-plugin/component-controls.js

Large diffs are not rendered by default.

25 changes: 4 additions & 21 deletions integrations/nextjs-plugin/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import fs from 'fs';
import {
compile,
watch,
Expand All @@ -11,7 +10,6 @@ let builtStarted = false;
export default ({
bundleName,
configPath,
distFolder,
presets,
staticFolder,
webPack,
Expand All @@ -21,12 +19,13 @@ export default ({
const userProps: CompileProps = {
bundleName,
configPath,
staticFolder,
webPack,
};
const options: CompileProps = {
presets: presets || defaultPresets,
distFolder: distFolder || path.join(process.cwd(), defaultConfig.distDir),
distFolder: path.resolve(__dirname, '..'),
staticFolder:
staticFolder || path.join(process.cwd(), defaultConfig.distDir),
...userProps,
};

Expand All @@ -36,23 +35,7 @@ export default ({
process.env.NODE_ENV === 'development'
? watch(options)
: compile(options);
compiler.then(({ bundleName }) => {
//temporary hack to send the bundle name to static props
fs.writeFile(
path.resolve(__dirname, './store.js'),
`
const { HMRStore } = require('@component-controls/store');
const bundle = require("${bundleName}");
const store = new HMRStore(bundle);
exports.store = store;
`,
err => {
if (err) {
console.error(err);
}
},
);
});
compiler.then(() => {});
}
return {
...rest,
Expand Down
2 changes: 1 addition & 1 deletion integrations/nextjs-plugin/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FC } from 'react';
import { jsx } from 'theme-ui';
import { DocType } from '@component-controls/core';
import { AppContext } from '@component-controls/app';
const { store } = require('./store');
import { store } from '../store';

import { NextLink } from './NextLink';

Expand Down
5 changes: 3 additions & 2 deletions integrations/nextjs-plugin/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { StoryStore, Store } from '@component-controls/store';
export const store: StoryStore = new Store();
import { StoryStore, HMRStore } from '@component-controls/store';
const bundle = require('../component-controls');
export const store: StoryStore = new HMRStore(bundle);

0 comments on commit 636ffac

Please sign in to comment.