-
This is a rollup-based project that produces two type of bundles:
dist/cjs/bundle.js
: for common js projectsdist/esm/bundle.js
: for ES6 based module projects. Here you want to mainly benefit from tree-shaking.
-
Accordingly, two different jest config files have been coined
-
Aliases need to be maintained between the different configuration files:
jest.config.cjs/esm.js
rollup.config.js
-
.babelrc
ensures that we do not need to worry aboutimport {h} from "preact"
all the time
npx jest --config jest.config.esm.js
npx jest --config jest.config.cjs.js
-
npm run build
triggers Rollup to create 2 copies of 2 bundles:- Primary copies of the bundles for NPM clients:
dist/cjs/bundle.js
dist/esm/bundle.js
- Secondary copies of the bundles for storybook client (e.g. for internal development):
node_modules/@al-mabsut/muslimah/dist/cjs/bundle.js
node_modules/@al-mabsut/muslimah/dist/esm/bundle.js
- Primary copies of the bundles for NPM clients:
-
Each bundle contains:
- The source code of all the components that we import in
src/index.js
- A
contentStore
as an exported constant that encompasses the contents of all Markdown files as present undercontents/hanafi/en
- The source code of all the components that we import in
-
The intended workflow in terms of internal development of this library is that inside
index.stories.js
you do two type of imports:- The standard import of the index:
import { Muslimah } from './index';
. - The contentStore import from the bundle:
import { contentStore } from '@al-mabsut/muslimah';
- The standard import of the index:
-
@al-mabsut/muslimah
is an alias that we have configured inside.storybook/main.js
:{ find: '@al-mabsut/muslimah', replacement: path.resolve(__dirname, '../node_modules/@al-mabsut/muslimah/dist/esm/bundle.js') }
. The reason we have to do it this way is because storybooks run inside the browser, they do not have access to the local filesystem. Besides, it is great to develop in function of our principal NPM client, which this style mimics. -
Take note that since we do
import { Muslimah } from './index';
for the components, we are able to benefit from the hot-reloading features of storybook when we change the CSS and the code around.
In this fashion we have the best of both worlds:
- Fast, iterative development of our components that we can proudly show-case in our storybooks
- Caching of the markdown content that is not bound to change that often
Just beware to not forget running: npm run build
after having done a npm install
of this project
Note:
- I have noticed so far that
Storybook
has caching functionality that may cause havoc from time to time:rm -rf node_module/.cache
is your friend.