我正在使用 webpack html 插件从 graphiql.ejs 生成 html 页面,但是当我运行 npm start
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/