Repository navigation
Replies: 1 comment
|
The TypeScript block describes the options object; you don't paste import swc from '@rollup/plugin-swc';
// In plugins, after your existing babel(...) plugin:
swc({
swc: {
swcrc: false,
configFile: false,
jsc: {
parser: { syntax: 'ecmascript' },
target: 'esnext',
minify: {
compress: { drop_console: true }, // example; choose your own options
mangle: false,
},
},
minify: true,
},
})This enables minification and avoids targeting an older language level in SWC. There is an important distinction, though: the official plugin calls If your requirement is specifically “call SWC's minifier on the finished chunks, without another SWC transpilation pass,” you can put a small plugin object directly in the same import { minify } from '@swc/core';
const swcMinifyOnly = {
name: 'swc-minify-only',
async renderChunk(code) {
const result = await minify(code, {
module: true, // this example is for output.format: 'es'
compress: { drop_console: true },
mangle: false,
sourceMap: true,
});
return { code: result.code, map: result.map ?? null };
},
};
// plugins: [your existing babel(...) plugin, swcMinifyOnly]
// output: { ..., format: 'es', sourcemap: true }Use this instead of the I checked both approaches with Rollup 4.66.0, |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The docs for @rollup/plugin-swc seem to be for TypeScript, and I'm using JavaScript and have no experience with TypeScript. This is my first experience with Node, Rollup, SWC, and packaging in general. I want to run the minification after I transpile with Babel, but Babel's minify makes that impossible because it processes the minification concurrently with the transpilation. I have tried using Terser and no joy there. The rollup-plugin-swc-minify works to my satisfaction in this regard, processing after Babel, but it doesn't allow clients to set minify options, instead it hard codes most all of them. I need to set some of those options.
Here is the example in the @rollup/plugin-swc readme:
But I don't understand how to use that inside my rollup-config.mjs file. How do I specify the SWC options inside the call to
swc()in thepluginsproperty? There is no example of that. I have tried a couple of things but always end up with default settings: transpilation and no minification. And a question that probably belongs elsewhere: How do I tell SWC not to transpile and only to minify? I can see how rollup-plugin-swc-minify does it, but that's inside a Rollup plugin using SWC API, not a Rollup config file using Options.I could fork or copy rollup-plugin-swc-minify to hard code my options, or publish a plugin that lets users specify all the options, but I'd much rather use a plugin that's part of Rollup itself and properly supported.
All reactions