在我的開發環境,我給如何導入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"
},
您的配置似乎並沒有讀取環境或進行開發,並督促 – Will
「開發」之間的任何區別:「nodemon --debug的src/app.js --exec babel-node --presets es2015「, 」start「:」node dist/src/server.js「 我正在使用babel-cli進行開發,所以我一直在使用Webpack進行開發 –