[英]webpack + babel not bundling the js properly
I am using webpack and babel in my project. 我在项目中使用webpack和babel。 While the webpack is wokring fine but babel is somehow not doing it's job in polyfilling the ES6+ features. 虽然webpack正常运行,但是babel不知何故在填充ES6 +功能方面做不到。 When I use the npm script, I get some error "Entrypoint undefined = index.html" in the command prompt. 当我使用npm脚本时,在命令提示符下出现一些错误“ Entrypoint undefined = index.html”。 Kindly help ! 请帮助!
Package.json 的package.json
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "neeraj",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.0.2",
"babel-preset-env": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.19.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"dependencies": {
"babel-polyfill": "^6.26.0"
}
}
webpack.config.js webpack.config.js
const path=require('path');
const HtmlWebPackPlugin=require('html-webpack-plugin');
module.exports={
entry:['babel-polyfill','./src/js/index.js'],
output:{
path:path.resolve(__dirname,'dist'),
filename:'js/bundle.js'
},
devServer:{
contentBase:'./dist'
},
plugins:[
new HtmlWebPackPlugin({
filename:'index.html',
template:'./src/index.html'
})
],
module:{
rules:[
{
test:/\.js$/,
exclude:/node_modules/,
use:{
loader:'babel-loader'
}
}
]
}
};
.bablerc .bablerc
{
"presets":[
["env",{
"targets":{
"browser":[
"last 5 versions",
"ie>=8"
]
}
}]
]
}
EDIT------------------ I started getting some new error now. 编辑------------------我现在开始遇到一些新错误。
It is the html-webpack-plugin
's problem, a fix was introduced in 3.0.7
but was removed again in 3.0.8
. 这是html-webpack-plugin
的问题,在3.0.7
中引入了一个修复程序,但在3.0.8
再次将其删除。 For more information, please click here . 有关更多信息,请单击此处 。
So if you run npm install --save-dev html-webpack-plugin@3.0.7
, and then npm run dev
will output Entrypoint html-webpack-plugin for "index.html" = index.html . 因此,如果您运行npm install --save-dev html-webpack-plugin@3.0.7
,然后npm run dev
将输出Entrypoint html-webpack-plugin的“ index.html” = index.html 。 And personally, it is a trivail problem not that important. 就个人而言,这不是一个重要的琐碎问题。
There was some dependency issue. 有一些依赖问题。 Deleted my node_modules folder and used this command instead: npm install -D babel-loader@7 babel-core babel-preset-env webpack 删除了我的node_modules文件夹,并使用了以下命令:npm install -D babel-loader @ 7 babel-core babel-preset-env webpack
Follow this link for more information : https://github.com/babel/babel-loader 请点击此链接以获取更多信息: https : //github.com/babel/babel-loader
Now I no longer get any error and also babel is working fine. 现在,我不再遇到任何错误,并且babel正常工作。
FYI....you might have to install babel-polyfill & html-webpack-plugin seperately. 仅供参考...。您可能必须分别安装babel-polyfill和html-webpack-plugin。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.