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

Example with minification #6

Open
danielnaab opened this issue Jun 29, 2018 · 5 comments
Open

Example with minification #6

danielnaab opened this issue Jun 29, 2018 · 5 comments

Comments

@danielnaab
Copy link

It would be useful to demonstrate a bulletproof way to minify output bundles with code-splitting. I'm having trouble on certain edge cases, after working through multiple methods.

@guybedford
Copy link
Contributor

@danielnaab
Copy link
Author

@guybedford thanks for the suggestion - sadly it fails on a chunk import when outputting to es format:

/private/var/folders/1z/z7j597t12d182tv_n80x6sq458d1h_/T/5ea703e1-1d91-4a90-835f-faa90525f15b:1: ERROR - Failed to load module "./chunk-7b6e0b9b.js"
import { b as baseEach } from './chunk-7b6e0b9b.js';
^

1 error(s), 0 warning(s)

@camille-hdl
Copy link

camille-hdl commented Jul 19, 2018

@danielnaab While I would certainly not call this "bulletproof" (I still run into problems here and there), rollup-plugin-terser works for me with these settings:

terser({
    compress: {
        unused: false,
        collapse_vars: false
    },
    output: {
        comments: false
    },
    sourceMap: false
})

@kristoferbaxter
Copy link

The 0.8.x release of rollup-plugin-closure-compiler added support for dynamic imports.

I just tested a local copy of this repo and it appears to work.

// rollup.config.js
import compiler from '@ampproject/rollup-plugin-closure-compiler';

export default {
  input: ["src/main-a.js", "src/main-b.js"],
  output: [
    // ES module version, for modern browsers
    {
      dir: "public/module",
      format: "es",
      sourcemap: true
    },
    // SystemJS version, for older browsers
    {
      dir: "public/nomodule",
      format: "system",
      sourcemap: true
    }
  ],
  plugins: [
    compiler(),
  ],
  experimentalCodeSplitting: true
};

@enure
Copy link

enure commented Nov 26, 2018

We adjust the minifier based on the output format:

function getConfig(outputFormat) {
  ...
  plugins: [
    ...
    outputFormat === 'esm' ? terser() : uglify()
  ]
}

export default [
  getConfig('system'),
  getConfig('esm')
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants