【问题标题】:Webpack html output locationWebpack html 输出位置
【发布时间】:2020-08-13 11:21:53
【问题描述】:

我的 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 时,它完全弄乱了输出目录。它所做的是获取“路径”变量 VALUE,在本例中为“客户端”,然后在 Client/IGNOREdevjunk/Application/Web/Views/Health/Index.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】:

    以下内容对我有用

    我必须更改文件名,如下所示

    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/"
                  },
    

    【讨论】:

      猜你喜欢
      • 2017-02-27
      • 2018-06-27
      • 2018-11-21
      • 2020-06-12
      • 2013-10-07
      • 2017-04-19
      • 2018-03-19
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多