Scope hoisting Webpack loader based on Rollup.

Use Webpack 3's ModuleConcatenationPlugin instead.
Last updated 4 years ago by goto-bus-stop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install flat-loader 
SYNC missed versions from official npm registry.


Webpack 3 includes the ModuleConcatenationPlugin, which results in similar bundles as this loader, but is much better in dealing with split bundles and more complex setups. If possible, it's probably best to use that!


A fancier Rollup loader for Webpack. This loader uses Rollup for bundling only.


npm install --save-dev flat-loader


Note: If you are using Hot Reloading in development, make sure to only apply flat-loader in your production build. flat-loader presents all modules that are bundled by Rollup to Webpack as a single module, so hot reloading any of the bundled modules will force a reload of the entire bundle.

If I've done things right, using this loader should be very simple. At the top of your module.rules block in your Webpack config, add this:

{ include: [ /* Full paths to entry files */ ], use: 'flat-loader' }

It's probably clearer in a larger example:

module.exports = {
  context: path.join(__dirname, 'src'),
  entry: './app.js',
  module: {
    rules: [
        include: [
          // List the full paths to your application's entry points.
          // In this example we only have src/app.js.
          path.join(__dirname, 'src', 'app.js')
        // Important: ONLY use `flat-loader` here!
        use: 'flat-loader'
      // No need to touch your other loader configs.

You don't need to do any Rollup configuration.

You can see a small example project that uses flat-loader in the example/ folder.

How It Works

Your app entry points are passed into Rollup. A custom Rollup plugin is added that uses Webpack to resolve and load imported modules, so your Webpack resolver configuration and loaders all apply. ES Modules are bundled by Rollup, and all other types (UMD/CommonJS/etc) are treated as externals. These will be bundled by Webpack.



Current Tags

  • 1.1.2                                ...           latest (4 years ago)

5 Versions

  • 1.1.2 [deprecated]           ...           4 years ago
  • 1.1.1 [deprecated]           ...           4 years ago
  • 1.1.0 [deprecated]           ...           4 years ago
  • 1.0.1 [deprecated]           ...           4 years ago
  • 1.0.0 [deprecated]           ...           4 years ago
Maintainers (1)
Today 0
This Week 1
This Month 3
Last Day 1
Last Week 0
Last Month 7
Dependencies (2)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2017 © taobao.org |