Skip to content

Commit

Permalink
Merge pull request #13 from storybookjs/valentin/streamline-swc-optio…
Browse files Browse the repository at this point in the history
…ns-handlng-in-webpack-final

fix: streamline SWC options handling in webpackFinal
  • Loading branch information
valentinpalkovic authored Dec 30, 2024
2 parents 4aafe9f + b38e7cf commit 8976adf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@ const virtualModuleFiles = [
];

export const webpackFinal = async (config: Configuration, options: Options) => {
const swcOptions = await options.presets.apply("swc", {}, options);
const typescriptOptions = await options.presets.apply(
"typescript",
{},
options,
);

const swcFinalOptions: SwcOptions = {
...swcOptions,
const swcDefaultOptions: SwcOptions = {
env: {
...(swcOptions?.env ?? {}),
// Transpiles the broken syntax to the closest non-broken modern syntax.
// E.g. it won't transpile parameter destructuring in Safari
// which would break how we detect if the mount context property is used in the play function.
bugfixes: swcOptions?.env?.bugfixes ?? true,
bugfixes: true,
},
jsc: {
...(swcOptions.jsc ?? {}),
parser: swcOptions.jsc?.parser ?? {
parser: {
syntax: "typescript",
tsx: true,
dynamicImport: true,
},
},
};

const swcOptions = await options.presets.apply(
"swc",
swcDefaultOptions,
options,
);

const typescriptOptions = await options.presets.apply(
"typescript",
{},
options,
);

config.module = {
...(config.module || {}),
rules: [
Expand All @@ -46,7 +48,7 @@ export const webpackFinal = async (config: Configuration, options: Options) => {
use: [
{
loader: require.resolve("swc-loader"),
options: swcFinalOptions,
options: swcOptions,
},
],
include: [getProjectRoot()],
Expand Down

0 comments on commit 8976adf

Please sign in to comment.