-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #24749 from storybookjs/valentin/create-export-ord…
…er-webpack5-loader Webpack5: Add export-order-loader and remove babel-plugin-named-exports-order
- Loading branch information
Showing
6 changed files
with
53 additions
and
23 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
25 changes: 25 additions & 0 deletions
25
code/builders/builder-webpack5/src/loaders/export-order-loader.ts
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,25 @@ | ||
import { parse } from 'es-module-lexer'; | ||
import MagicString from 'magic-string'; | ||
import type { LoaderContext } from 'webpack'; | ||
|
||
export default async function loader(this: LoaderContext<any>, source: string) { | ||
const callback = this.async(); | ||
|
||
try { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const [_, exports] = parse(source); | ||
|
||
if (exports.includes('__namedExportsOrder')) { | ||
return callback(null, source); | ||
} | ||
|
||
const magicString = new MagicString(source); | ||
const orderedExports = exports.filter((e) => e !== 'default'); | ||
magicString.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`); | ||
|
||
const map = magicString.generateMap({ hires: true }); | ||
return callback(null, magicString.toString(), map); | ||
} catch (err) { | ||
return callback(err as any); | ||
} | ||
} |
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
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