Skip to content

Named chunks ignoring names when requiring modules at runtime #358

Description

@brenwell

Hey guys, firstly webpack is great.

I am having some trouble with code splitting. I am trying to have 2 named chunks for two routes in my application which are not often visited. mysite.com/settings and mysite.com/access.

here is my webpack.config.coffee

module.exports =

  contentBase: "#{__dirname}/src/"

  cache: true

  entry:
    app: './src/coffee/app'
    head: './src/coffee/head'

  output:
    path: path.join(__dirname, 'build')
    publicPath: '/'
    filename: '[name].js'
    chunkFilename: '[name]-[chunkhash].js'

  plugins: []

And here is my router.coffee

access: (slug) ->
    _this = @
    require.ensure ['../view/page/access-page.coffee'], (require) ->
      AccessPage = require '../view/page/access-page.coffee'
      accessPage = AccessPage.getInstance()
      accessPage.render() unless accessPage.isRendered
      _this.showPage accessPage
    , 'access'


settings: (slug) ->
    _this = @
    require.ensure ['../view/page/settings-page.coffee'], (require) ->
      SettingsPage = require '../view/page/settings-page.coffee'
      settingsPage = SettingsPage.getInstance()
      settingsPage.render() unless settingsPage.isRendered
      _this.showPage settingsPage
    , 'settings'

I am not using the webpack dev-server, instead I am watching simply by using the following cmd-line tool

webpack -d --progress --colors --watch

The problem is that it ignores the names when requiring the files, as you can see the format is '[name]-[chunkhash].js' it generates files with the correct format e.g. settings-2j3nekj2n3ejkn2.js but during development, when I attempt to load the page, the browser complains that '-2j3nekj2n3ejkn2.js' cannot be found, somehow the mapping of the files, ignores the names. If I leave out the names, then it works.

Generated files
screen shot 2014-07-14 at 22 58 30

Chrome error
screen shot 2014-07-14 at 22 59 39

So the question is how can I setup mulitple named chunks correctly (or is there a bug). Thanks in advance.

Note I have checked out their examples in the docs at https://github.com/webpack/docs/wiki/code-splitting

and I have followed their optimization docs aswell at https://github.com/webpack/docs/wiki/optimization

and I also posted the question on stackoverflow
http://stackoverflow.com/questions/24743114/webpack-multiple-named-chunks-ignoring-names-at-runtime

But I am still stuck

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions