Webpack无法将javascript注入cshtml

问题描述

嗨,我有一个MVC 5项目,其中包含很多javascript前端代码。因此,我决定将那些javascript ==>注入到cshtml模板中进行模块化==>在我的视图中部分渲染它们 我的配置:

webpack.config.js

module.exports = {
entry: {
    layout: './Public/js/Layout.js',index: './ViewModules/Home/Index.js',noisoisieuam: './ViewModules/KetQua/NoiSoiSieuAm.js'
},output: {
    path: path.resolve(__dirname,'./Public/Output'),filename: '[name].bundle.[contenthash].js',},plugins: [
    new HtmlWebpackPlugin({
        inject: true,templateContent: '',filename: '../../../ViewModules/Shared/_Layout.temp.cshtml',chunks: [ 'layout']
    }),new HtmlWebpackPlugin({
        inject: true,filename: '../../../ViewModules/Home/Index.temp.cshtml',chunks: ['index']
    }),filename: '../../../ViewModules/KetQua/NoiSoiSieuAm.temp.cshtml',chunks: ['noisoisieuam']
    })
],// IMPORTANT NOTE: If you are using Webpack 2 or above,replace "loaders" with "rules"
module: {
    rules: [
        {
            use: [
                {
                    loader: 'babel-loader',options: {
                        presets: ["@babel/preset-env"]
                        }
                }
            ],test: /\.js$/,exclude: /node_modules/
        },{
            test: /\.json$/,type: 'javascript/auto',use: [
                {
                    loader: 'file-loader',options: {
                        name: "[path][name].[ext]"
                    }
                }
            ],}
    ]
}

}

*.temp.cshtml文件是空的cshtml文件,仅用于javascript注入。 在我各自的*.cshtml(我的视图)中编写代码:

    ...
@Html.Partial("~/ViewModules/<path-to-template>/*.temp.cshtml")
...

问题是webpack仅注入了前2个temp.cshtml(_Layout和我的主页)。

npm run build或在Visual Studio中构建不会给出任何错误。这些javascript捆绑包全部创建。 'noisoisieuam'块未注入我的temp.cshtml

我该如何解决?非常感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...