-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19937 from storybookjs/valentin/fix-angular-15-in…
…compatibility Fix "__webpack_require__.nmd is not a function issue" in Angular 15
- Loading branch information
Showing
8 changed files
with
98 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
code/frameworks/angular/src/server/plugins/storybook-normalize-angular-entry-plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const PLUGIN_NAME = 'storybook-normalize-angular-entry-plugin'; | ||
|
||
/** | ||
* Angular's webpack plugin @angular-devkit/build-angular/src/webpack/plugins/styles-webpack-plugin.js | ||
* transforms the original webpackOptions.entry point array into a structure like this: | ||
* | ||
* ```js | ||
* { | ||
* main: { | ||
* import: [...] | ||
* }, | ||
* | ||
* styles: { | ||
* import: [...] | ||
* }, | ||
* } | ||
* ``` | ||
* | ||
* Storybook throws an __webpack_require__.nmd is not a function error, when another runtime bundle (styles~runtime.iframe.bundle.js) is loaded. | ||
* To prevent this error, we have to normalize the entry point to only generate one runtime bundle (main~runtime.iframe.bundle.js). | ||
*/ | ||
export default class StorybookNormalizeAngularEntryPlugin { | ||
constructor(options) { | ||
this.options = options; | ||
} | ||
|
||
apply(compiler) { | ||
const webpackOptions = compiler.options; | ||
const entry = | ||
typeof webpackOptions.entry === 'function' ? webpackOptions.entry() : webpackOptions.entry; | ||
|
||
webpackOptions.entry = async () => { | ||
const entryResult = await entry; | ||
|
||
if (entryResult.main && entryResult.styles) { | ||
return { | ||
main: { | ||
import: Array.from(new Set([...entryResult.main.import, ...entryResult.styles.import])), | ||
}, | ||
}; | ||
} | ||
|
||
return entry; | ||
}; | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { | ||
this.compilation = compilation; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters