2017-06-01 71 views
1

我有以下DEV-服務器配置的WebPack開發服務器不建立應用之前開始

devServer: { 
    port: 3000, 
    host: '0.0.0.0', 
    watchOptions: { 
     aggregateTimeout: 300, 
     poll: 1000, 
    }, 
    compress: true, 
    inline: true, 
    contentBase: BUILD_PATH, 
    historyApiFallback: true, 
} 

BUILD_PATH = path.resolve(__dirname, '../build/webapp') 

的問題是,../build/webapp文件夾爲空時,DEV-服務器啓動。 由於結果應用程序加載正常(index.html,bundle.js),但無法加載應位於資產子文件夾中的任何字體或其他資源。

如果我只運行webpack - 一切都出現在該文件夾中。在webpack之後,我可以啓動開發服務器和一切都很好。

開發服務器日誌:

Project is running at http://0.0.0.0:3000/ 
    webpack output is served from/
    Content not from webpack is served from D:\Development\Projects\myproject\build\webapp 
    404s will fallback to /index.html 
10% building modules 5/8 modules 3 active 
    ...oject\webapp\node_modules\url\url.js(node:5560) 
63% building modules 746/839 modules 93 active ...node_modules\lodash-es\_freeGlob 
    al.js 

任何想法?

回答

3

webpack devserver模式構建並處理內存中的結果並不保存到磁盤。它以構建模式將它們保存到磁盤(不在devserver模式下)。

典型的解決方案是做乳寧的WebPack在計時模式並行devserver:

webpack -w 

也有write-file-webpack-plugin爲devserver用於一些人:

+0

我怎麼能強迫devserver以包括字體由webpack'url-loader'裝載? (他們是分開的資產文件夾中的woff文件,如果我運行webpack) – Vovan

+0

我可以在dev-server日誌中看到他們'/assets/fonts/source-sans-pro-v9-latin-700italic.woff2 13.7 kB [emit] /assets/fonts/inconsolata-v15-latin_latin-ext-700.woff 35.9 kB [emit] ... ' 但無法通過瀏覽器訪問它們。 404錯誤 – Vovan

+0

您可以從瀏覽器從webpack dev服務器url:port訪問它們。 – oklas