[英]Webpack multiple named chunks ignoring names at runtime
I am having trouble with webpacks code splitting functionality. 我在使用webpacks代码拆分功能时遇到问题。 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.
mysite.com/settings和mysite.com/access。
here is my webpack.config.coffee 这是我的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 这是我的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开发服务器,而只是通过使用以下cmd-line工具观看
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]-[hash].js' it generates files with the correct format eg 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. 问题是它在需要文件时忽略了名称,因为你可以看到格式是'[name] - [hash] .js'它生成的文件格式正确,例如settings-2j3nekj2n3ejkn2.js但是在开发期间,当我尝试加载页面,浏览器抱怨找不到'-2j3nekj2n3ejkn2.js',不知何故,文件的映射忽略了名称。 If I leave out the names, then it works.
如果我省略名字,那就行了。
So the question is how can I setup mulitple named chunks correctly. 所以问题是如何才能正确设置多个名为chunk的块。 Thanks in advance.
提前致谢。
Note I have checked out their examples in the docs at https://github.com/webpack/docs/wiki/code-splitting 注意我已经在https://github.com/webpack/docs/wiki/code-splitting的文档中查看了他们的示例
and I have followed their optimization docs aswell at https://github.com/webpack/docs/wiki/optimization 我已经关注了他们的优化文档以及https://github.com/webpack/docs/wiki/optimization
But I am stuck 但我被卡住了
Well the simple answer is - [name= is not supported in chunkName. 那么简单的答案是 - [name =在chunkName中不受支持。
The awesome guys at Webpack have actually heard my cries and implemented it Webpack上那些很棒的人实际上听到了我的哭声并实现了它
Here is the commit https://github.com/webpack/webpack/commit/03c87c11a4219ae6ec6bfe87e570a0dacceac859 这是提交https://github.com/webpack/webpack/commit/03c87c11a4219ae6ec6bfe87e570a0dacceac859
As a result of the following issue I made https://github.com/webpack/webpack/issues/358 由于以下问题我做了https://github.com/webpack/webpack/issues/358
It is already available as of Beta ^1.3.2 它已经从Beta ^ 1.3.2开始提供
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.