admin管理员组文章数量:1418660
I would like to inject the webpack-dev-server.js file.
However according to the documentation this should be done manually and only with the full url:
From: .html#api
Notice that [...] there is no inline mode for WebpackDevServer API.
<script src="http://localhost:8080/webpack-dev-server.js"></script>
should be inserted to HTML page manually.
From: .html#hot-mode
<!-- It is important that you point to the full url --> <script src="http://localhost:8080/webpack-dev-server.js"></script>
What is the reason for those two points from the documentation?
Why wouldn't it be a good idea to inject a script tag like <script src="/webpack-dev-server.js"></script>
?
I have also opened an issue on github:
I would like to inject the webpack-dev-server.js file.
However according to the documentation this should be done manually and only with the full url:
From: http://webpack.github.io/docs/webpack-dev-server.html#api
Notice that [...] there is no inline mode for WebpackDevServer API.
<script src="http://localhost:8080/webpack-dev-server.js"></script>
should be inserted to HTML page manually.
From: http://webpack.github.io/docs/webpack-dev-server.html#hot-mode
<!-- It is important that you point to the full url --> <script src="http://localhost:8080/webpack-dev-server.js"></script>
What is the reason for those two points from the documentation?
Why wouldn't it be a good idea to inject a script tag like <script src="/webpack-dev-server.js"></script>
?
I have also opened an issue on github: https://github./webpack/webpack/issues/1285
Share Improve this question edited Jul 23, 2015 at 13:21 jantimon asked Jul 16, 2015 at 8:01 jantimonjantimon 38.2k23 gold badges126 silver badges193 bronze badges2 Answers
Reset to default 5 +50I think the key is in --inline. You can set it through devServer.inline: true
. I learned recently that it injects webpack-dev-server/client
entry automatically. In fact if you add it to your entry and use --inline
, you'll end up with a duplicate script!
If inline is set, you need to set just webpack/hot/only-dev-server
to your entries.
The webpack dev server client script retrieves the address of the server it connects to from its own script tag's src
attribute, in your case http://localhost:8080/
.
Note that you can directly include the client script in your bundle via adding it to the entry list:
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/index'
],
output: {
filename: 'bundle.js',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
};
In which case the webpack-dev-server/client/index.js
script (which corresponds to the /webpack-dev-server.js
script served from the dev server) will use its resource query as the server address to connect to.
See also the relevant snippet of code in webpack-dev-server/client/index.js
.
本文标签: javascriptInject webpackdevserverjsStack Overflow
版权声明:本文标题:javascript - Inject webpack-dev-server.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745295647a2652059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论