admin管理员组

文章数量:1296258

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.

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.

Share Improve this question edited Feb 18, 2021 at 2:10 Daniel Kaplan asked Feb 18, 2021 at 2:00 Daniel KaplanDaniel Kaplan 67.5k57 gold badges268 silver badges401 bronze badges 2
  • doesn't rollup only minify if you use an external minification plugin like terser? – selfagency Commented Feb 18, 2021 at 2:17
  • @selfagency the documentation suggests otherwise: there is an option on whether or not to output a source map – Daniel Kaplan Commented Feb 18, 2021 at 2:20
Add a ment  | 

2 Answers 2

Reset to default 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" mand 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./vitejs/vite/issues/762
  base: './',
  plugins: [
    svelte(),
  ],
  build: {
    // dont minify JS and CSS
    minify: false,
    rollupOptions: {
      output: {
        // remove hashes from output paths
        // https://github./vitejs/vite/issues/378
        entryFileNames: `assets/[name].js`,
        chunkFileNames: `assets/[name].js`,
        assetFileNames: `assets/[name].[ext]`
      }
    }
  },
});

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.

本文标签: javascriptCan I tell rollup to not minimize the code it generatesStack Overflow