Skip to content

Commit

Permalink
fix: integrated styled-components babel plugin does not works (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Jan 26, 2024
1 parent c0fc44f commit 1f950ce
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -52,6 +52,7 @@
"@vercel/ncc": "0.33.3",
"babel-plugin-dynamic-import-node": "2.3.3",
"babel-plugin-module-resolver": "4.1.0",
"babel-plugin-styled-components": "2.1.4",
"babel-plugin-transform-define": "2.0.1",
"enhanced-resolve": "5.9.3",
"fast-glob": "3.2.12",
Expand Down
115 changes: 112 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/builder/bundle/index.ts
Expand Up @@ -40,6 +40,7 @@ async function bundle(opts: IBundleOpts): Promise<void | IBundleWatcher> {
const config = opts.configProvider.configs[i];
const { plugins: extraPostCSSPlugins, ...postcssLoader } =
config.postcssOptions || {};
const babelSCOpts = getBabelStyledComponentsOpts(opts.configProvider.pkg);
// workaround for combine continuous onBuildComplete log in watch mode
const logStatus = lodash.debounce(
() =>
Expand Down Expand Up @@ -105,12 +106,14 @@ async function bundle(opts: IBundleOpts): Promise<void | IBundleWatcher> {
pluginTransformRuntime: {},
pluginLockCoreJS: {},
pluginDynamicImportNode: false,
pluginStyledComponents: getBabelStyledComponentsOpts(
opts.configProvider.pkg,
),
},
],
beforeBabelPlugins: [require.resolve('babel-plugin-dynamic-import-node')],
beforeBabelPlugins: [
require.resolve('babel-plugin-dynamic-import-node'),
...(babelSCOpts
? [[require.resolve('babel-plugin-styled-components'), babelSCOpts]]
: []),
],
extraBabelPresets: config.extraBabelPresets,
extraBabelPlugins: config.extraBabelPlugins,

Expand Down
5 changes: 4 additions & 1 deletion src/builder/bundless/loaders/javascript/babel.ts
Expand Up @@ -45,8 +45,8 @@ const babelTransformer: IJSTransformer = function (content) {
path.dirname(this.paths.fileAbsPath),
),
presetTypeScript: {},
pluginStyledComponents: getBabelStyledComponentsOpts(this.pkg),
};
const pluginSCOpts = getBabelStyledComponentsOpts(this.pkg);

// transform alias to relative path for babel-plugin-module-resolver
const alias = Object.entries(oAlias).reduce<typeof oAlias>(
Expand Down Expand Up @@ -99,6 +99,9 @@ const babelTransformer: IJSTransformer = function (content) {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.json'],
},
],
...(pluginSCOpts
? [[require.resolve('babel-plugin-styled-components'), pluginSCOpts]]
: []),
...(define
? [
[
Expand Down

0 comments on commit 1f950ce

Please sign in to comment.