[英].babelrc configuration placed in package.JSON
Currently exploring webpack different tools associated with it. 目前正在探索webpack与之相关的不同工具。 Now I am using Babel for transpiling
ES6
code into ES5
code. 现在我使用Babel将
ES6
代码转换为ES5
代码。 I came accross the need for a .babelrc
file which holds the configurations for Babel. 我满足了对
.babelrc
文件的需求,该文件包含Babel的配置。 However, on the website of Babel I also saw that you could also place these configurations into the package.json
file. 但是,在Babel的网站上我也看到你也可以将这些配置放入
package.json
文件中。 Like this: 像这样:
Package.json File: Package.json文件:
{
"name": "webpack-tutorial",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"webpack": "^4.16.2",
"webpack-cli": "^3.1.0"
},
"babel": {
"presets": [
"env"
]
}
}
Now when I run npm run dev
Babel also works and the code gets transpiled succesfully. 现在,当我运行
npm run dev
Babel也可以运行,代码也会成功转换。
How does Babel know to access the package.json file? Babel如何知道访问package.json文件? Does it first look for an
.babelrc
file and then if this is not present does it automatically look for its configurations in the package.json
? 它首先查找
.babelrc
文件然后如果不存在它会自动在package.json
查找其配置吗? How does Webpack interact with both Babel
and the package.json
file to produce this result? Webpack如何与
Babel
和package.json
文件交互以产生此结果?
For anyone who is interested it was on the official website: 对于任何有兴趣的人,都在官方网站上:
Babel will look for a .babelrc in the current directory of the file being transpiled.
Babel将在正在编译的文件的当前目录中查找.babelrc。 If one does not exist, it will travel up the directory tree until it finds either a .babelrc, or a package.json with a "babel": {} hash within.
如果一个不存在,它将沿目录树向上移动,直到找到.babelrc或带有“babel”:{}哈希的package.json。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.