Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.
This repository was archived by the owner on May 29, 2019. It is now read-only.

ExtractTextPlugin extracts from asynchronous split point chunks #120

Closed
@ghost

Description

I have a webpack.config.js like:

module.exports = {
  entry: {
    index: ['./app/routes/ClientRouter', './app/pages/Index'],
    create:  ['./app/routes/ClientRouter', './app/pages/Create'],
    play:  ['./app/routes/ClientRouter', './app/pages/Play'],
    vendor: ['react', 'react-dom', 'flux']
  },
  output: {
    path: __dirname + '/public/build',
    publicPath: '/build/',
    filename: '[name].js',
    chunkFileName: '[id].chunk.js'
  },
  resolve: {
    alias: alias
  },
  module: {
    noParse: noParse,
    loaders: [
      { test: /.js$/, loader: 'babel-loader', exclude: /node_modules/ },
      { test: /.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader'), exclude: /node_modules/ }
    ]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js', minChunks: Infinity }),
    new ExtractTextPlugin('[name].css', {
      allChunks: false
    })
  ]
};

And a client router like:

function route() {
  var location = window.location.pathname,
      appContainer = document.getElementById('app-container'),
      routeMatches;

  if(!location || location == '/') {
    require.ensure(['../pages/Index'], function() {
      var Page = require('../pages/Index');
      ReactDOM.render(<Page />, appContainer);
    });
  } else if(routeMatches = location.match(/^\/create$/)) {
    require.ensure(['../pages/Create'], function() {
      var Page = require('../pages/Create');
      ReactDOM.render(<Page />, appContainer);
    });
  } else if(routeMatches = location.match(/^\/play\/([01]+)$/)) {
    require.ensure(['../pages/Play'], function() {
      var Page = require('../pages/Play');
      ReactDOM.render(<Page mazeData={routeMatches[1]}/>, appContainer);
    });
  }
}

The ExtractTextPlugin creates index.js/index.css, create.js/create.css, etc, with the extracted CSS for each containing only what is directly required from each of those entry points. It also generates 1.1.js, 2.2.js, and 3.3.js for the split points to load pages asynchronously, but the CSS is removed from them as well. I.e. (from 1.1.js):

/***/ 5:
/***/ function(module, exports) {

    // removed by extract-text-webpack-plugin

/***/ }

This means as you navigate between pages the CSS for the asynchronously-loaded splits do not get added to the page, only their JS. You only have the CSS from the initial entry point.

It seems like 1.1.js, etc should still contain their inline CSS and inject it, like when you aren't using the ExtractTextPlugin. That way you can get the benefits of the extracted entry point CSS for the initial pageload and avoid an FOUC, but after that everything works as a single page app.

I thought the plugin would work that way from the documentation, which says "by default it extracts only from the initial chunk(s)." And I tried explicitly setting 'allChunks: false'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions