This article introduces the babelrc configuration file of the root directory of the vue-cli scaffolding tool
introduce
The es6 feature browser is not fully supported, but using es6 is the general trend, so babel came into being to convert es6 code into code that the browser can recognize.
Babel provides special command line tools for easy transcoding, you can understand it yourself
vue-cli scaffolding.babelrc file
{ // This item specifies the rules for transcoding "presets": [ // The env item is made with the help of the plug-in babel-preset-env. The following configuration says that babel transcoding es6, es7, es8, and sets modular files such as amd and commonjs without transcoding ["env", { "modules": false }], // The following is the es syntax that appears at different stages, including different transcoding plugins "stage-2" ], // The following option is to refer to the plugin to handle the code conversion. Transform-runtime is used to handle global functions and optimize babel compilation "plugins": ["transform-runtime"], // The following refers to the generated file without comments "comments": false, // The following paragraph is the transcoding rule executed in a specific environment. When the environment variable is the test below, the above settings will be overwritten. "env": { // test is an environment variable set in advance. If BABEL_ENV is not set, NODE_ENV is used. If none of them are set, the default is development "test": { "presets": ["env", "stage-2"], // istanbul is a tool used to test transcoding code "plugins": ["istanbul"] } } }
ps: Let me introduce you to the .babelrc configuration file below
Regarding react project structure, there are many configuration files, which sometimes feel difficult to understand.
For example, the .babelrc file is used to set the rules and plug-ins for transcoding.
If you are familiar with Linux, you must know that files ending with rc usually represent files, configurations, etc. that are automatically loaded at runtime. In babel6, this file is essential.
The babel command can be configured in it. When using the babel cli in the future, you can configure less. There is also an env field that can be used forBABEL_ENV
orNODE_ENV
Different environment variables specified, perform different compilation operations.
Summarize
The above is a detailed explanation of the babel configuration file.babelrc example in vue-cli introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!