Skip to content

Commit

Permalink
implement single entry
Browse files Browse the repository at this point in the history
  • Loading branch information
mrm007 committed Feb 20, 2024
1 parent c3f0373 commit 3aa9edd
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,7 @@ module.exports = {

// Optional:
title: 'My Awesome Library',
entry: './src/entry',
themes: './src/themes',
snippets: './playroom/snippets.js',
frameComponent: './playroom/FrameComponent.js',
Expand Down Expand Up @@ -158,6 +159,15 @@ export default function useScope() {
};
```
## Custom Entry
You can provide a custom entry file via the `entry` option, which is a path to a file that runs some code before everything else. For example, if you wanted to apply a CSS reset or other global styles, polyfills etc.:
```js
import '../path/to/your/theming-system/reset';
import '../path/to/your/theming-system/global-styles.css';
```
## Theme Support
If your component library has multiple themes, you can customise Playroom to render every theme simultaneously via the `themes` configuration option.
Expand Down
1 change: 1 addition & 0 deletions lib/defaultModules/entry.js
@@ -0,0 +1 @@
// this doesn't do anything by default
2 changes: 2 additions & 0 deletions lib/defaultModules/useScope.js
@@ -1 +1,3 @@
import '../../src/entry';

export default () => {};
3 changes: 3 additions & 0 deletions lib/makeWebpackConfig.js
Expand Up @@ -56,6 +56,9 @@ module.exports = async (playroomConfig, options) => {
},
extensions: ['.mjs', '.tsx', '.ts', '.jsx', '.js', '.json'],
alias: {
__PLAYROOM_ALIAS__ENTRY__: playroomConfig.entry
? relativeResolve(playroomConfig.entry)
: require.resolve('./defaultModules/entry'),
__PLAYROOM_ALIAS__COMPONENTS__: relativeResolve(
playroomConfig.components
),
Expand Down
7 changes: 7 additions & 0 deletions src/entry.js
@@ -0,0 +1,7 @@
let imported = false;

if (!imported) {
imported = true;
// eslint-disable-next-line import/no-unresolved
require('__PLAYROOM_ALIAS__ENTRY__');
}
2 changes: 2 additions & 0 deletions src/frame.js
@@ -1,3 +1,5 @@
import './entry';

import { renderElement } from './render';
import Frame from './Playroom/Frame';

Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
@@ -1,4 +1,5 @@
interface PlayroomConfig {
entry?: string;
components: string;
outputPath: string;
title?: string;
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
@@ -1,3 +1,5 @@
import './entry';

import { renderElement } from './render';
import Playroom from './Playroom/Playroom';
import { StoreProvider } from './StoreContext/StoreContext';
Expand Down
2 changes: 2 additions & 0 deletions src/preview.js
@@ -1,3 +1,5 @@
import './entry';

import { renderElement } from './render';
import Preview from './Playroom/Preview';

Expand Down

0 comments on commit 3aa9edd

Please sign in to comment.