javascript - Webpack html 插件不生成 html

标签 javascript node.js webpack graphql html-webpack-plugin

我正在使用 webpack html 插件从 graphiql.ejs 生成 html 页面,但是当我运行 npm start

时它没有生成 html 页面

webpack.config.js

var HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
  plugins: [
    new HtmlWebpackPlugin({
      filename: "public/graphql/index.html", // Write the file to <public-path>/graphql/index.html
      inject: false, // Do not inject any of your project assets into the template
      GRAPHQL_VERSION: packageJSON.dependencies.graphql.replace(/[^0-9.]/g, ""), // Get the graphql version from my package.json
      template: "graphiql.ejs" // path to template
    })
  ]
};

我想在/public/graphql 目录中生成 index.html。有谁知道我做错了什么?还有其他命令可以运行 webpack 吗?

最佳答案

webpack.config.js

    const path = require('path');
    const HtmlWebpackPlugin = require("html-webpack-plugin");
    const packageJSON=require("./package.json");
    module.exports = {
        entry: './src/app.js',
        output: {
            path: path.resolve(__dirname, 'public'),
            filename:"build.js"
        },
        plugins: [
            new HtmlWebpackPlugin({
                filename: "graphql/index.html", // Write the file to <public-path>/graphql/index.html
                inject: false, // Do not inject any of your project assets into the template
                GRAPHQL_VERSION: packageJSON.dependencies.graphql.replace(/[^0-9.]/g, ""), // Get the graphql version from my package.json
                template: "graphiql.ejs" // path to template
            })
        ]      
    }

运行 webpack -p 生成 html

webpack -p

关于javascript - Webpack html 插件不生成 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46582319/

相关文章:

javascript - 为什么对象的数组属性总是返回对象

javascript - 迭代 JSON 以检索单个变量

javascript - 灯箱在 IE 8 中不工作

node.js - npm 运行脚本 : node server. js && Mocha 测试

javascript - Cloud Spanner 无法正确管理 session 吗?

javascript - 使用 webpack 加载 svg 资源

javascript - 如何在路由器的 View 中实现 View

sass - 将 sass-loader 与 css-modules 组合时出错

reactjs - next.js 包分析器不会创建页面来查看包

node.js - Sendgrid 替换标签