2017-07-10 61 views
0

在我的開發環境,我給如何導入dist文件夾中的HTML文件?

res.sendFile(path.resolve(__dirname,'../Views/setpwd.html'); 

,它是在開發環境中運作良好。

但在生產視圖沒有移動到dist文件夾,即使我已經在webpack中添加了html加載器。你們能幫我解決嗎?

在此先感謝

##的WebPack配置##

var path = require('path'); 
var webpack=require('webpack'); 
var nodeExternals = require('webpack-node-externals'); 
module.exports = { 
    entry: './src/app.js', 
    output: { 
     path: path.resolve(__dirname,'dist'), 
     filename: 'src/server.js', 
    }, 
     target: 'node', 
     externals: [nodeExternals()], 
     module: { 
     loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}], 
     loaders: [ 
      { test: /\.(html)$/, loader: "file" } 
     ] 
    }, 
    plugins: [ 
     new webpack.optimize.UglifyJsPlugin({ 
      compress: { 
       warnings: false, 
      }, 
      output: { 
       comments: false, 
      }, 
     }), 
    ] 
} 

deVdependencies

"devDependencies": { 
    "babel-core": "^6.24.1", 
    "babel-loader": "^7.0.0", 
    "babel-plugin-transform-runtime": "^6.23.0", 
    "babel-preset-env": "^1.5.1", 
    "babel-preset-es2015": "^6.24.1", 
    "file-loader": "^0.11.2", 
    "webpack": "^2.6.1", 
    "webpack-node-externals": "^1.6.0" 
    }, 
+0

您的配置似乎並沒有讀取環境或進行開發,並督促 – Will

+0

「開發」之間的任何區別:「nodemon --debug的src/app.js --exec babel-node --presets es2015「, 」start「:」node dist/src/server.js「 我正在使用babel-cli進行開發,所以我一直在使用Webpack進行開發 –

回答

1

如果我正確認識這一點,你要在HTML文件複製../Views/*.html到使用webpack的dist/目錄。如果是這樣,那麼你需要使用copy-webpack-plugin

new CopyWebpackPlugin([ 
    { 
    from: path.resolve(__dirname, '../path/to/views/directory'), 
    to: path.resolve(__dirname, '../path/to/dist') 
    ignore: ['.*'] 
    } 
]) 
+0

謝謝它正在工作 –

+0

If我的回答是正確的,請將它標記爲這樣。 –

相關問題