Can I tell rollup to not minimize the code it generates?
Asked Answered
E

2

9

I understand that I can generate a source map, but I want to generate the rollup output without minification. Is it possible to do this? I've googled and haven't found anybody asking this question.

Enclose answered 18/2, 2021 at 2:0 Comment(2)
doesn't rollup only minify if you use an external minification plugin like terser?Ericerica
@Ericerica the documentation suggests otherwise: there is an option on whether or not to output a source mapEnclose
D
3

usually with rollup:

javascript is minified by @rollup/plugin-terser
to disable minifacation of javascript
remove terser() from the plugins array in rollup.config.js

by default, CSS is not minified by rollup-plugin-css-only or rollup-plugin-postcss

rollup-plugin-css-only has no option for minify
css({ output: 'bundle.css' })

rollup-plugin-postcss has the default option { minimize: false }
postcss({ extract: 'bundle.css' })

other rollup plugins can produce minified CSS, for example rollup-plugin-svelte

as a workaround, to produce pretty CSS, im using the build script
rollup -c && prettier -w public/build/bundle.css
with npm i -D prettier

all of this may be simpler when migrating from rollup to vite
see also How do I disable minification when running "build" command in sveltekit?
and sveltejs: Switch existing project from rollup to vite
and awesome-vite

example vite.config.js

import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
  // use relative paths to asset files
  // https://github.com/vitejs/vite/issues/762
  base: './',
  plugins: [
    svelte(),
  ],
  build: {
    // dont minify JS and CSS
    minify: false,
    rollupOptions: {
      output: {
        // remove hashes from output paths
        // https://github.com/vitejs/vite/issues/378
        entryFileNames: `assets/[name].js`,
        chunkFileNames: `assets/[name].js`,
        assetFileNames: `assets/[name].[ext]`
      }
    }
  },
});
Deraign answered 6/10, 2023 at 17:11 Comment(0)
T
2

First of all, this question (or one similar) was asked here.

It seems that there isn't a way to do it based on that. I don't know what your exact use case for this is, but maybe you can run it through rollup-plugin-esformatter to make your code readable.

Triage answered 18/2, 2021 at 2:20 Comment(3)
I did find that answer, but it seemed to be for an unrelated project, so I didn't put too much weight into the repliesEnclose
The use case for me is easy debugging. Is there a method others use for this?Flattish
@Flattish Source maps?Triage

© 2022 - 2024 — McMap. All rights reserved.