How to remove comments from sourcemap created with Rollup and terser for web app javascript bundle?

75 Views Asked by At

How can I configure Rollup and it's terser plugin to create a sourcemap for my web app's minified javascript bundle, that doesn't have any of my javascript source code comments? I am using terser to minify my bundle, so I also need to generate a sourcemap to aid in debugging in browser dev tools. The below configuration does successfully produce a 'main.bundle.js' bundle and a 'main.bundle.js.map' sourcemap file, but I can't seem to find an option on the Rollup sourcemap docs to remove comments.

// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';

export default [
    {
        input: './src/js/main.js',
        output: {
            file: './dist/main.bundle.js',
            format: 'iife',
            name: 'mainjs',
            sourcemap: true
        },
        treeshake: {
            moduleSideEffects: false
        },
        plugins: [
            resolve(),
            terser()
        ]
    }
]

I've tried configuring terser like the following, but I get a pretty nondescript error message of: [!] (plugin terser) Error: Minify worker stopped with exit code 1

terser({
    sourceMap: {
        comments: false
    }
})
0

There are 0 best solutions below