Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网页包配置未在公用文件夹中生成index.html_Javascript_Webpack_Web Development Server - Fatal编程技术网

Javascript 网页包配置未在公用文件夹中生成index.html

Javascript 网页包配置未在公用文件夹中生成index.html,javascript,webpack,web-development-server,Javascript,Webpack,Web Development Server,我的webpack配置有点问题,因为某些原因,它没有在我的/public文件夹中创建index.html文件 请参见下面的webpack.config.js: const path=require(“路径”); const ExtractTextPlugin=require(“提取文本网页包插件”); 让调试; if(process.env.NODE_env==“生产”){ 调试=错误; }否则{ DEBUG=true;//process.env.NODE_env==“开发” } //cons

我的webpack配置有点问题,因为某些原因,它没有在我的/public文件夹中创建index.html文件

请参见下面的webpack.config.js:

const path=require(“路径”);
const ExtractTextPlugin=require(“提取文本网页包插件”);
让调试;
if(process.env.NODE_env==“生产”){
调试=错误;
}否则{
DEBUG=true;//process.env.NODE_env==“开发”
}
//const DEBUG=true;//process.env.NODE_env==“开发”
module.exports={
上下文:path.resolve(uu dirname,“src”),
条目:“./index.js”,
输出:{
path:path.resolve(_dirname,“public”),
文件名:DEBUG?“bundle.js”:“bundle.min.js”
},
模块:{
装载机:[
{
测试:/\.js$/,,
加载器:“巴别塔加载器”,
排除:/node\u模块/
},
{
测试:/\.jsx$/,,
加载器:“巴别塔加载器”,
排除:/node_模块/,
选项:{
预设:[“反应”,“es2015”]
}
},
{
测试:/\.scss$/,,
加载程序:调试
? [
“样式加载器”,
“css加载器?源地图”,
“sass加载程序?源映射”,
“邮政编码加载器”
]
:ExtractTextPlugin.extract(“css加载器!sass加载器!postcss加载器”)
},
{
测试:/\(ttf | eot | svg)(\?[\s\s]+)?$/,
使用:“文件加载器?名称=images/[name].[ext]”
}
]
},
开发服务器:{
历史上的倒退:是的,
热:是的,
},
插件:[
新的ExtractTextPlugin(“style.css”{
allChunks:对
})
]

};您需要HTML网页包插件。该插件为您创建html文件,并将webpacks entry prop中定义的每个条目添加到您的html中。 别忘了安装它

$ npm install html-webpack-plugin --save-dev
然后在您的网页包配置中:

var HtmlWebpackPlugin = require('html-webpack-plugin');

...

plugins: [
    new ExtractTextPlugin("style.css", {
      allChunks: true
    }),
    new HtmlWebpackPlugin()
  ]
有关更多信息,请参见此处:

谢谢,丹尼尔,这是一种享受。知道我如何将生成的index.html文件中的css/js src从public/bundle.min.js更改为bundle.min.js吗,因为所有文件都已在公用文件夹中。如果有帮助,请接受我的回答。(单击箭头)到qs:将道具publicPath添加到输出道具。publicPath:“/”这就是htmlwebpackplugin在src字段中的前缀。在添加新的HtmlWebpackPlugin()时,它会破坏我的开发版本,它声明目标容器不是控制台中的DOM元素。