diff --git a/.gitignore b/.gitignore index f2656f4..a5d9286 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ storybook-static/ /formatNodeToJsxString.mjs /formatValueToString.mjs /getValueType.mjs +/storybookConfig.mjs /styles.css diff --git a/.storybook/main.mjs b/.storybook/main.mjs index 38ac063..5d555af 100644 --- a/.storybook/main.mjs +++ b/.storybook/main.mjs @@ -1,4 +1,5 @@ -import * as packageJson from '../package.json'; +import packageJson from '../package.json'; +import { webpackFinal } from '../src/storybookConfig.mjs'; export default { addons: [ @@ -43,14 +44,5 @@ export default { return indexer; }); }, - webpackFinal: async (config) => { - config.module.rules.map((rule) => { - if (!rule.type || rule.type !== 'asset/source') { - // ? Ensure any loaders are not run on any 'raw' file imports - rule.resourceQuery = { not: [/raw/] }; - } - return rule; - }); - return config; - }, + webpackFinal, }; diff --git a/README.md b/README.md index 4ea2116..43831bd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ npm i @idesigncode/storybook-tools --save - ✏️ Write functional "example components" for actual use cases of a component. - 📑 [PropsTable](https://idesigncode-storybook-tools.netlify.app/?path=/docs/components-propstable--docs): automatically document static & "live-updating" props details. -- 🖥️ [Source](https://idesigncode-storybook-tools.netlify.app/?path=/docs/components-source--docs) & [Raw Imports](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-raw-imports--docs): output production-ready source code. +- 🖥️ [Source](https://idesigncode-storybook-tools.netlify.app/?path=/docs/components-source--docs): output production-ready source code with [Raw Imports](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-webpack--docs#raw-imports) & [Import Path Replacements](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-import-path-replacements--docs). - 🌙 [DocsContainer](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-docscontainer--docs): dark mode support for Storybook Docs with [storybook-dark-mode](https://github.com/hipstersmoothie/storybook-dark-mode). - 📸 Image snapshot testing compatible. - 🎉 Compatible with `MDX` and `CSF` stories. @@ -25,6 +25,5 @@ npm i @idesigncode/storybook-tools --save ## Requirements - See [peer dependencies](package.json) -- The [Raw Imports](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-raw-imports--docs) feature requires the default [Webpack builder](https://storybook.js.org/docs/react/builders/webpack) for Storybook. -- A small amount of [configuration](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-css--docs) for default styles. -- Optional global configuration for using [Import Path Replacements](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-import-path-replacements--docs) with [Source](https://idesigncode-storybook-tools.netlify.app/?path=/docs/components-source--docs). +- The default [Webpack builder](https://storybook.js.org/docs/react/builders/webpack) for Storybook. +- A small amount of configuration for [Webpack](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-webpack--docs) & the [default CSS styles](https://idesigncode-storybook-tools.netlify.app/?path=/docs/configuration-css--docs). diff --git a/__snapshots__/components-source.test.js.snap b/__snapshots__/components-source.test.js.snap index d56e916..e9912e4 100644 --- a/__snapshots__/components-source.test.js.snap +++ b/__snapshots__/components-source.test.js.snap @@ -159,16 +159,6 @@ exports[`Components/Source Component With Props Raw test 1`] = ` import - - - - * - - - - - as - packageJson diff --git a/__snapshots__/configuration-import-path-replacements--env.png b/__snapshots__/configuration-import-path-replacements--env.png index 88ac30b..d1f670a 100644 Binary files a/__snapshots__/configuration-import-path-replacements--env.png and b/__snapshots__/configuration-import-path-replacements--env.png differ diff --git a/__snapshots__/configuration-import-path-replacements.test.js.snap b/__snapshots__/configuration-import-path-replacements.test.js.snap index e6eab6c..b445fdf 100644 --- a/__snapshots__/configuration-import-path-replacements.test.js.snap +++ b/__snapshots__/configuration-import-path-replacements.test.js.snap @@ -16,16 +16,6 @@ exports[`Configuration/Import Path Replacements Env test 1`] = ` import - - - - * - - - - - as - packageJson diff --git a/__snapshots__/configuration-raw-imports--example.png b/__snapshots__/configuration-raw-imports--example.png deleted file mode 100644 index c39ac9f..0000000 Binary files a/__snapshots__/configuration-raw-imports--example.png and /dev/null differ diff --git a/__snapshots__/configuration-raw-imports--webpack-final-rules-config.png b/__snapshots__/configuration-raw-imports--webpack-final-rules-config.png deleted file mode 100644 index 6c6903c..0000000 Binary files a/__snapshots__/configuration-raw-imports--webpack-final-rules-config.png and /dev/null differ diff --git a/__snapshots__/configuration-raw-imports.test.js.snap b/__snapshots__/configuration-raw-imports.test.js.snap deleted file mode 100644 index b1007e7..0000000 --- a/__snapshots__/configuration-raw-imports.test.js.snap +++ /dev/null @@ -1,348 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Configuration/Raw Imports Example test 1`] = ` -
-
-
- // Stories of Component.mjs
-
-
-
-
-
-
- import
-
-
- ComponentWithPropsRaw
-
-
- from
-
-
-
-
- './ComponentWithProps.mjs?raw'
-
-
- ;
-
-
-
-
-
-
-
- // .storybook/main.mjs
-
-
-
-
-
-
- export
-
-
-
-
- default
-
-
-
-
- {
-
-
-
-
-
-
- webpackFinal
-
-
- :
-
-
-
-
- async
-
-
-
-
- (
-
-
- config
-
-
- )
-
-
-
-
- =>
-
-
-
-
- {
-
-
-
-
- config
-
-
- .
-
-
- module
-
-
- .
-
-
- rules
-
-
- .
-
-
- map
-
-
- (
-
-
- (
-
-
- rule
-
-
- )
-
-
-
-
- =>
-
-
-
-
- {
-
-
-
-
-
-
- if
-
-
-
-
- (
-
-
- !
-
-
- rule
-
-
- .
-
-
- type
-
-
- ||
-
-
- rule
-
-
- .
-
-
- type
-
-
- !==
-
-
-
-
- 'asset/source'
-
-
- )
-
-
-
-
- {
-
-
-
-
-
-
- // ? Ensure any loaders are not run on any 'raw' file imports
-
-
-
-
- rule
-
-
- .
-
-
- resourceQuery
-
-
- =
-
-
-
-
- {
-
-
-
-
- not
-
-
- :
-
-
-
-
- [
-
-
- /
-
-
- raw
-
-
- /
-
-
- ]
-
-
-
-
- }
-
-
- ;
-
-
-
-
-
-
- }
-
-
- ,
-
-
-
-
-
-
- return
-
-
- rule
-
-
- ;
-
-
-
-
-
-
- }
-
-
- )
-
-
- ;
-
-
-
-
-
-
- // ...config settings
-
-
-
-
-
-
- return
-
-
- config
-
-
- ;
-
-
-
-
-
-
- }
-
-
- ,
-
-
-
-
-
-
- // ...main.mjs configuration
-
-
-
-
-
-
- }
-
-
- ;
-
-
-
-
-
+
+
+ // .storybook/main.mjs
+
+
+
+
+
+
+ import
+
+
+
+
+ {
+
+
+ webpackFinal
+
+
+ }
+
+
+
+
+ from
+
+
+
+
+ "@idesigncode/storybook-tools/storybookConfig.mjs"
+
+
+ ;
+
+
+
+
+
+
+ export
+
+
+
+
+ default
+
+
+
+
+ {
+
+
+
+
+
+
+ webpackFinal
+
+
+ :
+
+
+
+
+ async
+
+
+
+
+ (
+
+
+ config
+
+
+ )
+
+
+
+
+ =>
+
+
+
+
+ {
+
+
+
+
+
+
+ const
+
+
+ updatedConfig
+
+
+ =
+
+
+
+
+ await
+
+
+
+
+ webpackFinal
+
+
+ (
+
+
+ config
+
+
+ )
+
+
+ ;
+
+
+
+
+
+
+ // ...Apply your custom configuration settings here to \`updatedConfig\`
+
+
+
+
+
+
+ return
+
+
+ updatedConfig
+
+
+ ;
+
+
+
+
+
+
+ }
+
+
+ ,
+
+
+
+
+
+
+ // ...main.mjs configuration
+
+
+
+
+
+
+ }
+
+
+ ;
+
+
+
+
+
+
+
+ // .storybook/main.mjs
+
+
+
+
+
+
+ import
+
+
+
+
+ {
+
+
+ webpackFinal
+
+
+ }
+
+
+
+
+ from
+
+
+
+
+ "@idesigncode/storybook-tools/storybookConfig.mjs"
+
+
+ ;
+
+
+
+
+
+
+ export
+
+
+
+
+ default
+
+
+
+
+ {
+
+
+
+
+ webpackFinal
+
+
+ ,
+
+
+
+
+
+
+ // ...main.mjs configuration
+
+
+
+
+
+
+ }
+
+
+ ;
+
+
+
+
+
+
+
+ // Stories of Component.mjs
+
+
+
+
+
+
+ import
+
+
+ ComponentWithPropsRaw
+
+
+ from
+
+
+
+
+ './ComponentWithProps.mjs?raw'
+
+
+ ;
+
+
+
+
+
+
+
+ // @idesigncode/storybook-tools/storybookConfig.mjs
+
+
+
+
+
+
+ export
+
+
+
+
+ const
+
+
+
+
+ webpackFinal
+
+
+
+
+ =
+
+
+
+
+ async
+
+
+
+
+ (
+
+
+ config
+
+
+ )
+
+
+
+
+ =>
+
+
+
+
+ {
+
+
+
+
+
+
+ // ? Enable 'raw imports' for all files
+
+
+
+
+ config
+
+
+ .
+
+
+ module
+
+
+ .
+
+
+ rules
+
+
+ .
+
+
+ map
+
+
+ (
+
+
+ (
+
+
+ rule
+
+
+ )
+
+
+
+
+ =>
+
+
+
+
+ {
+
+
+
+
+
+
+ if
+
+
+
+
+ (
+
+
+ !
+
+
+ rule
+
+
+ .
+
+
+ type
+
+
+ ||
+
+
+ rule
+
+
+ .
+
+
+ type
+
+
+ !==
+
+
+
+
+ 'asset/source'
+
+
+ )
+
+
+
+
+ {
+
+
+
+
+ rule
+
+
+ .
+
+
+ resourceQuery
+
+
+ =
+
+
+
+
+ {
+
+
+
+
+ not
+
+
+ :
+
+
+
+
+ [
+
+
+ /
+
+
+ raw
+
+
+ /
+
+
+ ]
+
+
+
+
+ }
+
+
+ ;
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+ return
+
+
+ rule
+
+
+ ;
+
+
+
+
+
+
+ }
+
+
+ )
+
+
+ ;
+
+
+
+
+
+
+ // ? Enable correct display of dynamic source code in production
+
+
+
+
+ config
+
+
+ .
+
+
+ optimization
+
+
+ .
+
+
+ minimizer
+
+
+ .
+
+
+ map
+
+
+ (
+
+
+ (
+
+
+ minimizer
+
+
+ )
+
+
+
+
+ =>
+
+
+
+
+ {
+
+
+
+
+ minimizer
+
+
+ .
+
+
+ options
+
+
+ .
+
+
+ minimizer
+
+
+ .
+
+
+ options
+
+
+ .
+
+
+ compress
+
+
+ =
+
+
+
+
+ false
+
+
+ ;
+
+
+
+
+ minimizer
+
+
+ .
+
+
+ options
+
+
+ .
+
+
+ minimizer
+
+
+ .
+
+
+ options
+
+
+ .
+
+
+ format
+
+
+ =
+
+
+
+
+ {
+
+
+
+
+ comments
+
+
+ :
+
+
+
+
+ true
+
+
+
+
+ }
+
+
+ ;
+
+
+
+
+
+
+ return
+
+
+ minimizer
+
+
+ ;
+
+
+
+
+
+
+ }
+
+
+ )
+
+
+ ;
+
+
+
+
+
+
+ return
+
+
+ config
+
+
+ ;
+
+
+
+
+
+
+ }
+
+
+ ;
+
+
+
+
+
+
++ Using `webpackFinal` with custom configuration settings +
+