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

legacy plugin forces minify #6266

Closed
7 tasks done
agriffis opened this issue Dec 26, 2021 · 0 comments · Fixed by #6272
Closed
7 tasks done

legacy plugin forces minify #6266

agriffis opened this issue Dec 26, 2021 · 0 comments · Fixed by #6272

Comments

@agriffis
Copy link
Contributor

agriffis commented Dec 26, 2021

Describe the bug

When the legacy plugin is added, minification can't be disabled. For example, with this config:

{
  build: {minify: false},
  plugins: [react(), legacy({targets: ['defaults', 'not IE 11']})]
}

The output js is minified. This includes both the original js and the legacy js. The plugin forces it on for both.

Reproduction

Here is an example repo: https://github.com/agriffis/vite-issue-repro-legacy-minify

I included dist in the repo so you can see the result without bothering to clone it. Inside dist, both index.bc5679cc.js and index-legacy.4d822f6a.js are minified, even though the config has minification disabled.

System Info

System:
    OS: Linux 5.14 Fedora 33 (Server Edition) 33 (Server Edition)
    CPU: (12) x64 Intel Core Processor (Skylake, IBRS)
    Memory: 2.85 GB / 15.62 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.18.1 - /usr/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.3 - /usr/local/bin/npm
  npmPackages:
    @vitejs/plugin-legacy: ^1.6.4 => 1.6.4 
    @vitejs/plugin-react: ^1.0.7 => 1.1.3 
    vite: ^2.7.2 => 2.7.7

Used Package Manager

npm

Logs

2021-12-26T23:47:20.913Z vite:config bundled config file loaded in 99.79ms
2021-12-26T23:47:20.922Z vite:config using resolved config: {
  build: {
    target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
    polyfillModulePreload: true,
    outDir: '/home/aron/src/vite-issue-repro-legacy-minify/dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    cssCodeSplit: true,
    cssTarget: 'chrome61',
    sourcemap: false,
    rollupOptions: {
      input: '/home/aron/src/vite-issue-repro-legacy-minify/index.html',
      output: [Array]
    },
    minify: 'terser',
    terserOptions: {},
    write: true,
    emptyOutDir: null,
    manifest: false,
    lib: false,
    ssr: false,
    ssrManifest: false,
    reportCompressedSize: true,
    chunkSizeWarningLimit: 500,
    watch: null,
    commonjsOptions: { include: [Array], extensions: [Array] },
    dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  },
  plugins: [
    'alias',
    'vite:react-babel',
    'vite:react-refresh',
    'vite:react-jsx',
    'vite:modulepreload-polyfill',
    'vite:resolve',
    'vite:html-inline-script-proxy',
    'vite:css',
    'vite:esbuild',
    'vite:json',
    'vite:wasm',
    'vite:worker',
    'vite:asset',
    'vite:legacy-config',
    'vite:legacy-generate-polyfill-chunk',
    'vite:legacy-env',
    'vite:define',
    'vite:css-post',
    'vite:watch-package-data',
    'vite:build-html',
    'commonjs',
    'vite:data-uri',
    'rollup-plugin-dynamic-import-variables',
    'vite:asset-import-meta-url',
    'vite:legacy-post-process',
    'vite:build-import-analysis',
    'vite:esbuild-transpile',
    'vite:terser',
    'vite:reporter',
    'vite:load-fallback'
  ],
  resolve: { dedupe: [ 'react', 'react-dom' ], alias: [ [Object], [Object] ] },
  optimizeDeps: {
    include: [ 'react/jsx-dev-runtime' ],
    esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  },
  define: { 'import.meta.env.LEGACY': '__VITE_IS_LEGACY__' },
  configFile: '/home/aron/src/vite-issue-repro-legacy-minify/vite.config.js',
  configFileDependencies: [ 'vite.config.js' ],
  inlineConfig: {
    root: undefined,
    base: undefined,
    mode: undefined,
    configFile: undefined,
    logLevel: undefined,
    clearScreen: undefined,
    build: {}
  },
  root: '/home/aron/src/vite-issue-repro-legacy-minify',
  base: '/',
  publicDir: '/home/aron/src/vite-issue-repro-legacy-minify/public',
  cacheDir: '/home/aron/src/vite-issue-repro-legacy-minify/node_modules/.vite',
  command: 'build',
  mode: 'production',
  isProduction: true,
  server: { fs: { strict: true, allow: [Array], deny: [Array] } },
  preview: {
    port: undefined,
    strictPort: undefined,
    host: undefined,
    https: undefined,
    open: undefined,
    proxy: undefined,
    cors: undefined
  },
  env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  assetsInclude: [Function: assetsInclude],
  logger: {
    hasWarned: false,
    info: [Function: info],
    warn: [Function: warn],
    warnOnce: [Function: warnOnce],
    error: [Function: error],
    clearScreen: [Function: clearScreen],
    hasErrorLogged: [Function: hasErrorLogged]
  },
  packageCache: Map(0) { set: [Function (anonymous)] },
  createResolver: [Function: createResolver]
}
vite v2.7.7 building for production...
transforming...
✓ 33 modules transformed.
rendering chunks...
[@vitejs/plugin-legacy] legacy polyfills: Set(4) {
  'core-js/modules/es.promise',
  'core-js/modules/es.array.iterator',
  'core-js/modules/web.dom-collections.iterator.js',
  'core-js/modules/es.string.replace.js'
}
2021-12-26T23:47:24.401Z vite:config using resolved config: {
  root: '/home/aron/src/vite-issue-repro-legacy-minify/node_modules/@vitejs/plugin-legacy',
  configFile: undefined,
  logLevel: 'error',
  plugins: [
    'alias',
    'vite:modulepreload-polyfill',
    'vite:resolve',
    'vite:html-inline-script-proxy',
    'vite:css',
    'vite:esbuild',
    'vite:json',
    'vite:wasm',
    'vite:worker',
    'vite:asset',
    'vite:legacy-polyfills',
    'vite:define',
    'vite:css-post',
    'vite:watch-package-data',
    'vite:build-html',
    'commonjs',
    'vite:data-uri',
    'rollup-plugin-dynamic-import-variables',
    'vite:asset-import-meta-url',
    'vite:build-import-analysis',
    'vite:esbuild-transpile',
    'vite:terser',
    'vite:reporter',
    'vite:load-fallback'
  ],
  build: {
    target: false,
    polyfillModulePreload: true,
    outDir: '/home/aron/src/vite-issue-repro-legacy-minify/node_modules/@vitejs/plugin-legacy/dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    cssCodeSplit: true,
    cssTarget: false,
    sourcemap: false,
    rollupOptions: { input: [Object], output: [Object] },
    minify: 'terser',
    terserOptions: {},
    write: false,
    emptyOutDir: null,
    manifest: false,
    lib: false,
    ssr: false,
    ssrManifest: false,
    reportCompressedSize: true,
    chunkSizeWarningLimit: 500,
    watch: null,
    commonjsOptions: { include: [Array], extensions: [Array] },
    dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  },
  configFileDependencies: [],
  inlineConfig: {
    root: '/home/aron/src/vite-issue-repro-legacy-minify/node_modules/@vitejs/plugin-legacy',
    configFile: false,
    logLevel: 'error',
    plugins: [ [Object] ],
    build: {
      write: false,
      target: false,
      minify: 'terser',
      assetsDir: 'assets',
      rollupOptions: [Object]
    }
  },
  base: '/',
  resolve: { dedupe: undefined, alias: [ [Object], [Object] ] },
  publicDir: '/home/aron/src/vite-issue-repro-legacy-minify/node_modules/@vitejs/plugin-legacy/public',
  cacheDir: '/home/aron/src/vite-issue-repro-legacy-minify/node_modules/@vitejs/plugin-legacy/node_modules/.vite',
  command: 'build',
  mode: 'production',
  isProduction: true,
  server: { fs: { strict: true, allow: [Array], deny: [Array] } },
  preview: {
    port: undefined,
    strictPort: undefined,
    host: undefined,
    https: undefined,
    open: undefined,
    proxy: undefined,
    cors: undefined
  },
  env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  assetsInclude: [Function: assetsInclude],
  logger: {
    hasWarned: false,
    info: [Function: info],
    warn: [Function: warn],
    warnOnce: [Function: warnOnce],
    error: [Function: error],
    clearScreen: [Function: clearScreen],
    hasErrorLogged: [Function: hasErrorLogged]
  },
  packageCache: Map(0) { set: [Function (anonymous)] },
  createResolver: [Function: createResolver],
  optimizeDeps: {
    esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  }
}
dist/assets/index-legacy.4d822f6a.js       1.83 KiB / gzip: 1.01 KiB
dist/assets/polyfills-legacy.f5cb7fcf.js   35.20 KiB / gzip: 14.81 KiB
dist/assets/vendor-legacy.da5e2df0.js      128.19 KiB / gzip: 41.36 KiB
dist/assets/favicon.17e50649.svg   1.49 KiB
dist/assets/logo.ecc203fb.svg      2.61 KiB
dist/index.html                    1.58 KiB
dist/assets/index.bc5679cc.js      1.64 KiB / gzip: 0.84 KiB
dist/assets/index.cd9c0392.css     0.75 KiB / gzip: 0.48 KiB
dist/assets/vendor.73f7496b.js     128.12 KiB / gzip: 41.35 KiB

Validations

agriffis added a commit to agriffis/vite that referenced this issue Dec 27, 2021
This fixes two misbehaviors of the legacy plugin:

1. Respect {minify: false} for legacy assets.
2. Don't inflict es2019/terser on non-legacy chunks.

For the first problem, we could have fixed by checking for false in
viteLegacyPlugin.config(). Unfortunately that would have left the second
problem unsolved. Without adding significant complexity to the config,
there's no easy way to use different minifiers in the build depending on
the individual chunk.

So instead we include terserPlugin() whenever minify is enabled, even
true or 'esbuild', then check the actual configuration in the plugin.
This allows the legacy plugin to inject its special override, leaving
all the non-legacy stuff intact and uncomplicated.

See also, previous attempts: vitejs#5157 vitejs#5168
agriffis added a commit to agriffis/vite that referenced this issue Dec 27, 2021
This fixes two misbehaviors of the legacy plugin:

1. Respect {minify: false} for legacy assets.
2. Don't inflict es2019/terser on non-legacy chunks.

For the first problem, we could have fixed by checking for false in
viteLegacyPlugin.config(). Unfortunately that would have left the second
problem unsolved. Without adding significant complexity to the config,
there's no easy way to use different minifiers in the build depending on
the individual chunk.

So instead we include terserPlugin() whenever minify is enabled, even
true or 'esbuild', then check the actual configuration in the plugin.
This allows the legacy plugin to inject its special override, leaving
all the non-legacy stuff intact and uncomplicated.

See also, previous attempts: vitejs#5157 vitejs#5168
agriffis added a commit to agriffis/vite that referenced this issue Dec 27, 2021
This fixes two misbehaviors of the legacy plugin:

1. Respect {minify: false} for legacy assets.
2. Don't inflict es2019/terser on non-legacy chunks.

For the first problem, we could have fixed by checking for false in
viteLegacyPlugin.config(). Unfortunately that would have left the second
problem unsolved. Without adding significant complexity to the config,
there's no easy way to use different minifiers in the build depending on
the individual chunk.

So instead we include terserPlugin() whenever minify is enabled, even
true or 'esbuild', then check the actual configuration in the plugin.
This allows the legacy plugin to inject its special override, leaving
all the non-legacy stuff intact and uncomplicated.

See also, previous attempts: vitejs#5157 vitejs#5168
agriffis added a commit to agriffis/vite that referenced this issue Dec 27, 2021
This fixes two misbehaviors of the legacy plugin:

1. Respect {minify: false} for legacy assets.
2. Don't inflict es2019/terser on non-legacy chunks.

For the first problem, we could have fixed by checking for false in
viteLegacyPlugin.config(). Unfortunately that would have left the second
problem unsolved. Without adding significant complexity to the config,
there's no easy way to use different minifiers in the build depending on
the individual chunk.

So instead we include terserPlugin() whenever minify is enabled, even
true or 'esbuild', then check the actual configuration in the plugin.
This allows the legacy plugin to inject its special override, leaving
all the non-legacy stuff intact and uncomplicated.

See also, previous attempts: vitejs#5157 vitejs#5168
poyoho added a commit to poyoho/vite that referenced this issue Dec 30, 2021
commit d856c4b
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Dec 30 00:25:59 2021 +0800

    fix(ssr): move `vite:ssr-require-hook` after user plugins (vitejs#6306)

commit b45f4ad
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Wed Dec 29 14:49:15 2021 +0100

    chore(deps): update all non-major dependencies (vitejs#6185)

commit 4d75b2e
Author: Niputi <7137178+Niputi@users.noreply.github.com>
Date:   Wed Dec 29 14:48:13 2021 +0100

    feat: catch postcss error messages (vitejs#6293)

commit f68ed8b
Author: Bogdan Chadkin <trysound@yandex.ru>
Date:   Wed Dec 29 16:40:13 2021 +0300

    fix: replace execa with cross-spawn (vitejs#6299)

commit 44bb4da
Author: patak <matias.capeletto@gmail.com>
Date:   Wed Dec 29 12:51:46 2021 +0100

    chore(deps): update to esbuild fixed at 0.14.3 (vitejs#5861)

commit 9ad7c55
Author: patak <matias.capeletto@gmail.com>
Date:   Wed Dec 29 11:32:49 2021 +0100

    deps: update to typescript 4.5.4 (vitejs#6297)

commit 1da104e
Author: Aron Griffis <aron@scampersand.com>
Date:   Wed Dec 29 02:50:19 2021 -0500

    fix: don't force terser on non-legacy (fix vitejs#6266) (vitejs#6272)

commit 5279de6
Author: ygj6 <7699524+ygj6@users.noreply.github.com>
Date:   Wed Dec 29 05:30:47 2021 +0800

    feat: import.meta.glob support ?raw (vitejs#5545)

commit 6d4ee18
Author: Bjorn Lu <bjornlu.dev@gmail.com>
Date:   Wed Dec 29 04:27:49 2021 +0800

    feat(define): prevent assignment (vitejs#5515)

commit ac3f434
Author: Bogdan Chadkin <trysound@yandex.ru>
Date:   Tue Dec 28 23:26:46 2021 +0300

    fix: upgrade postcss-modules (vitejs#6248)

commit 5a111ce
Author: Bogdan Chadkin <trysound@yandex.ru>
Date:   Tue Dec 28 23:23:42 2021 +0300

    fix: replace chalk with picocolors (vitejs#6277)

commit 7e3e84e
Author: patak-dev <matias.capeletto@gmail.com>
Date:   Tue Dec 28 15:07:10 2021 +0100

    release: v2.7.9

commit 83ad7bf
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Tue Dec 28 21:52:41 2021 +0800

     fix: revert vitejs#6251 (vitejs#6290)

    This reverts commit 49da986.

commit 1cbf0e1
Author: Cristian Pallarés <cristian@pallares.io>
Date:   Tue Dec 28 11:30:42 2021 +0100

    test: fix test typo (vitejs#6285)

commit d13ced5
Author: patak-dev <matias.capeletto@gmail.com>
Date:   Tue Dec 28 09:40:48 2021 +0100

    release: v2.7.8

commit dcb1df4
Author: itibbers <jxn2014@gmail.com>
Date:   Tue Dec 28 16:30:32 2021 +0800

    docs: add frontmatters to fix __VP_STATIC_START__ (vitejs#6283)

commit 60ce7f9
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Tue Dec 28 16:20:12 2021 +0800

    fix(ssr): capture scope declaration correctly (vitejs#6281)

commit eb08ec5
Author: Niputi <7137178+Niputi@users.noreply.github.com>
Date:   Tue Dec 28 06:10:37 2021 +0100

    chore: remove acorn plugins (vitejs#6275)

commit 64b1595
Author: zhangenming <282126346@qq.com>
Date:   Tue Dec 28 11:52:51 2021 +0800

    chore(create-vite): add more gitignore (vitejs#6247)

commit 49da986
Author: sanyuan <39261479+sanyuan0704@users.noreply.github.com>
Date:   Tue Dec 28 05:30:54 2021 +0800

    fix: seperate source and dep for dymamic import after build (vitejs#6251)

commit 394539c
Author: Bogdan Chadkin <trysound@yandex.ru>
Date:   Tue Dec 28 00:29:23 2021 +0300

    fix: upgrade to launch-editor with picocolors (vitejs#6209)

commit 40e3f73
Author: Shinigami <chrissi92@hotmail.de>
Date:   Mon Dec 27 11:42:24 2021 +0100

    chore: fix link (vitejs#6269)

commit e7306b5
Author: Shinigami <chrissi92@hotmail.de>
Date:   Mon Dec 27 11:22:44 2021 +0100

    chore: update bug report issue template (vitejs#6263)

commit 1f945f6
Author: Aaron Bassett <arbassett4@outlook.com>
Date:   Sun Dec 26 15:28:47 2021 -0500

    fix(html): show error overlay when parsing invalid file (vitejs#6184)

commit 1d722c5
Author: patak-dev <matias.capeletto@gmail.com>
Date:   Sun Dec 26 06:35:04 2021 +0100

    release: v2.7.7

commit 2e3fe59
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Sun Dec 26 13:13:24 2021 +0800

    fix(ssr): transform class props (vitejs#6261)

commit 1a6e2da
Author: ygj6 <7699524+ygj6@users.noreply.github.com>
Date:   Sat Dec 25 18:24:44 2021 +0800

    docs: typescript tips for using Type-Only Imports and Export (vitejs#6260)

commit 6a47083
Author: Haoqun Jiang <haoqunjiang@gmail.com>
Date:   Fri Dec 24 14:02:43 2021 +0800

    fix: update the vue version in the error message (vitejs#6252)

commit 485e298
Author: Anthony Fu <anthonyfu117@hotmail.com>
Date:   Thu Dec 23 21:45:13 2021 +0800

    fix(ssr): nested destucture (vitejs#6249)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants