Webpack html输出位置

问题描述 投票:0回答:1

我的webpack配置如下

const webdirectory = "../Application/Web"
plugins: [
                new HtmlWebpackPlugin({
                    inject: "body",
                    filename: `${webdirectory}/Views/Health/Index.cshtml`,
                    template: `${webdirectory}/Views/Health/Index_Template.cshtml`,
                    minify: false
                }),

output: {
                // assets served by webpack-dev-server
                path: path.resolve(__dirname, "IGNOREdevjunk/"),
                publicPath: "https://localhost:8080/"
              },

我想让webpack把cshtml生成的文件夹和它从模板抓取的地方一样。但webpack的做法是,它从正确的位置抓取模板,但当它保存cshtml时,它完全弄乱了输出目录。它所做的是抓取'path'变量VALUE,在本例中是'Client',然后在ClientIGNOREdevjunkApplicationWebViewsHealthIndex.cshtml中创建cshtml。

如何让它把cshtml和模板保存在同一个文件夹里?保存时它忽略了相对路径。

目录结构

Parent
 - Application
 - - Web
 - - - Views
 - - - - Health
 - - - - - Index_template.cshtml
 - - - - - Index.cshtml (THIS IS WHERE I WANT THE CSHTML TO BE EMITTED)
 - Client
 - webpack.config.js
 - - IGNOREdevjunk
 - - - Application
 - - - - Web
 - - - - - Views
 - - - - - - Health
  - - - -  - - Index.cshtml (I DON'T WANT THIS SAVED HERE)
file webpack output html-webpack-plugin
1个回答
0
投票

下面的工作对我来说

我不得不把文件名改成如下

const webdirectory = "../Application/Web"
plugins: [
                new HtmlWebpackPlugin({
                    inject: "body",
                    filename: path.join(__dirname, "../Application/Web/Views/Health/Index.cshtml"),
                    template: `${webdirectory}/Views/Health/Index_Template.cshtml`,
                    minify: false
                }),

output: {
                // assets served by webpack-dev-server
                path: path.resolve(__dirname, "IGNOREdevjunk/"),
                publicPath: "https://localhost:8080/"
              },
© www.soinside.com 2019 - 2024. All rights reserved.