我目前正在尝试在项目中首次使用webpack,并在Startup.cs文件中使用以下内容设置了ASP.NET Core项目
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
我有Styles文件夹,其中也包含一些.less文件,并且在项目的根目录中有一个webpack.config.js,其中包含:
const path = require("path");
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = (env) => {
return [{
mode: 'development', //TODO Make configurable
entry: { 'main': './app.js' },
output: {
path: path.resolve(__dirname, "wwwroot"),
filename: "js/[name].js",
publicPath: "/"
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].css'
})
],
module: {
rules: [
{
test: /\.(less)$/,
include: [
path.resolve(__dirname, "Styles")
],
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader'
]
}
]
}
}];
}
当我运行应用程序时,我在输出中看到它正在编译webpack捆绑包,并且我在wwwroot的js和css文件夹中看到了我的文件,这表明它正在查找webpack配置文件,并且还看到了行如下所示,这表明它正在尝试使用webpack-hot-middleware插件进行操作:
[./ node_modules / html-entities / index.js] 231个字节{main} [内置]
[./ node_modules / querystring-es3 / decode.js] 2.45 KiB {main} [内置]
[./ node_modules / querystring-es3 / encode.js] 2.48 KiB {main} [内置]
[./ node_modules / querystring-es3 / index.js] 127个字节{main} [内置]
[./ node_modules / webpack-hot-middleware / client-overlay.js](webpack)-hot-middleware / client-overlay.js 2.17 KiB {main} [内置]
[./ node_modules / webpack-hot-middleware / client.js?path = __ webpack_hmr&dynamicPublicPath = true](webpack)-hot-middleware / client.js?path = __ webpack_hmr&dynamicPublicPath = true 7.68 KiB {main} [built] < / p>
但是随后我看不到任何其他对HMR的引用,并且控制台中没有[HMR]连接线来表明它已链接。
此设置中是否缺少任何内容?
答案 0 :(得分:0)
我发现了问题.....我很愚蠢,却忘记了实际上包含webpack输出的is文件,因为那时我所用的只是将我较少的文件编译成CSS!