Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias plugin not working with swc plugin. #61

Closed
jpanduro-blackbird opened this issue Jan 9, 2024 · 4 comments
Closed

Alias plugin not working with swc plugin. #61

jpanduro-blackbird opened this issue Jan 9, 2024 · 4 comments

Comments

@jpanduro-blackbird
Copy link

I might be missing something, but we recently replaced our terser plugin with rollup-plugin-swc and @rollup/plugin-alias stop working.

Here is our configuration

const swcConfig = {
  include: ['src/**/*.ts', '../shared/**/*.ts'],
  exclude: ['src/**/*.test.ts'],
  jsc: {
    parser: {
      syntax: 'typescript',
    },
    target: 'es2015',
    externalHelpers: false,
    minify: { sourceMap: true },
  },
  minify: true,
  sourceMaps: true,
};
const pluginsForNoUAParser = [
  typescript({
    include: ['src/**/*.ts', '../shared/**/*.ts'],
    exclude: ['src/**/*.test.ts'],
  }),
  replace({
    values: replaceConfig[env],
    preventAssignment: true,
  }),
  alias({
    entries: [{ find: 'ua-parser-js', replacement: './src/null.js' }],
  }),
  commonjs(),
  nodeResolve(),
  swc(defineRollupSwcOption(swcConfig)),
];

Any suggestions or ideas would be helpful!

@SukkaW
Copy link
Owner

SukkaW commented Jan 10, 2024

rollup-plugin-swc3 acts more as an alternative to @rollup/plugin-typescript rather than rollup-plugin-terser. If you intend to replace terser, you could import swcMinify from rollup-plugin-swc3 instead.

@jpanduro-blackbird
Copy link
Author

I think the following config is already doing the minification by lines

jsc: {
    minify: { sourceMap: true }
  },
  minify: true,

Our intent is to not include ua-parser-js library in the bundle in certain cases because of its size. For those purposes we were using @rollup/plugin-alias, which replace it with mocked module, that returned null. And this plugin stopped working after starting using rollup-plugin-swc3

Is there any idea how I can solve this problem?

@SukkaW
Copy link
Owner

SukkaW commented Jan 12, 2024

Is there any idea how I can solve this problem?

Could you provide a minimum reproduction so I can pinpoint the issue?

rollup-plugin-swc3 has implemented a customized module resolving to work with TypeScript files while @swc/core can expand aliased imports during the transformation. Although I suspect that this might be the cause of the issue, I can't rectify it without a minimal reproduction.

In the meantime, swcMinify doesn't include a customized module resolving and swc transformation. Therefore simply importing swcMinify from rollup-plugin-swc3 might be the quickest workaround for this issue.

@jpanduro-blackbird
Copy link
Author

Thanks for suggestions! Basically, I was able to achieve it by using rollup-plugin-ignore instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants