我想使用的WebPack捆綁的角度應用,應用捆綁失敗使用的WebPack-DEV-server命令
這是webpack.config.js
:
var path = require('path');
module.exports = {
context: path.resolve(__dirname, 'app'),
entry:'./index.js',
output:{
path : __dirname + '/app',
filename:'bundle.js'
}
};
的app/index.html
看起來是這樣的:
<!DOCTYPE html>
<html>
<head>
<title>test ng-webpack egghead</title>
</head>
<body ng-app="app">
<script type="text/javascript" src="bundle.js"></script>
</body>
</html>
當我運行webpack-dev-server
命令如控制檯日誌中所示:
>webpack-dev-server --content-base app
http://localhost:8080/webpack-dev-server/
webpack result is served from/
content is served from F:\Learnings\FrontEnd\AngularJs\webpack\egghead.io - AngularJS - Angular and Webpack for Modular Applications\egg-ng-webpack\app
Hash: 98db763b035ecfaba293
Version: webpack 1.13.2
Time: 1089ms
Asset Size Chunks Chunk Names
bundle.js 1.22 MB 0 [emitted] main
chunk {0} bundle.js (main) 1.19 MB [rendered]
[0] ./app/index.js 120 bytes {0} [built]
[1] ./~/angular/index.js 48 bytes {0} [built]
[2] ./~/angular/angular.js 1.19 MB {0} [built]
webpack: bundle is now VALID.
或當我運行相同的命令作爲新公共管理腳本,日誌保持不變(它看起來一切都還好吧),但bundle.js
文件,而不是/app
文件夾下生成在兩個output.path
設置,它的在應用程序根目錄下生成(該文件實際上並未寫入磁盤),它只能通過網址http://127.0.0.1:8080/bundle.js
而不是 的http://127.0.0.1:8080/app/bundle.js
(假設爲試圖在瀏覽器中加載app/index.html)我得到了錯誤(GET http://127.0.0.1:8080/app/bundle.js 404 (Not Found)
),並且在多次重複相同的過程之後,現在我沒有在任何地方獲取包文件,但日誌仍然與上面相同。
當我更換了命令的WebPack-DEV-服務器只的WebPack的package.json
內:
"scripts": {
"start": "webpack --content-base app"
},
現在bundle.js /app
下存在,它通過http://127.0.0.1:8080/app/bundle.js
顯示和index.html的負荷完全沒有錯誤。