반응 프로젝트 용 webpack을 설정 중이었고 babel, babel-core, babel-loader 사이에 혼란스러워했습니다. , babel-preset-2015 및 babel-preset-react. 나는 바벨이 es7 또는 es6 코드를 es5로 변환해야하지만 내 package.json에서는 바벨 (babel)을 제외한 모든 종속성을 "devDependencies"로 설치했다는 것을 알고있다. 누군가이 모든 것의 차이점과 왜 내 프로젝트에 모두 필요한지 설명해 주시겠습니까? 그들 모두를 대체 할 단일 의존성이 있습니까? 그리고 그들이 그렇게 중요하다면, 왜 그것들은 "devDependencies"로 포함되어 있습니까?babel 대 babel-core 대 babel-loader 대 babel-preset-2015 대 babel-preset-react 대 babel-polyfill
2
A
답변
2
바벨
Babel doesn't do anything,It basically acts like const babel = code => code;
by parsing the code and then generating the same code back out again.
You will need to add some plugins for Babel to do anything like transpiling es6,JSX.
바벨 코어에 이동하기 전에
if you want to use babel in your real project, you need to install babel but
there's no babel package available.
babel split it up into two separate packages: babel-cli and babel-core
**babel-cli** : which can be used to compile files from the command line.
**babel-core** : if you want to use the Node API you can install babel-
core, Same as "babel-cli" except you would use it programmatically inside your app.
use "babel-cli" or "babel-core" to compile your files before production.
, 플러그인 대
사전 :
,536,913,632 10We can add features(es6,JSX) one at a time with babel plugins(es2015),
or
we can use babel presets to include all the features(es6) of a particular year.
Presets make setup easier.
바벨 프리셋-es2015
babel-preset-env supports es2015 features and replaces es2015, es2016,
es2017 and latest.
So use babel-preset-env, it behaves exactly the same as babel-preset-latest
(or babel-preset-es2015, babel-preset-es2016, and babel-preset-es2017 together).
바벨 프리셋-반응
transform JSX into createElement calls like transforming react pure class to
function and transform react remove prop-types.
바벨-polyfill
Without babel-polyfill, babel only allows you to use features like arrow
functions, destructuring, default arguments, and other syntax-specific
features introduced in ES6.
The new ES6 built-ins like Set, Map and Promise must be polyfilled
To include the polyfill you need to require it at the top of the entry point
to your application.
바벨 로더
you done with babel-core, babel-cli, and why need preset, plugins and now
you are compiling ES6 to ES5 on a file-by-file basis by babel-cli every time.
to get rid-off this, you need to bundle the task/js file. For that you need
Webpack.
Loaders are kind of like “tasks”, They gives the ability to leverage
webpack's bundling capabilities for all kinds of files by converting them
to valid modules that webpack can process.
Webpack has great Babel support through babel-loader
devDependencies
When you deploy your app, modules in dependencies need to be installed or
your app won't work. Modules in devDependencies don't need to be installed
on the production server since you're not developing on that machine.
These packages are only needed for development and testing.
그들 모두를 대체하는 단일 의존성이 아닌가?
as you read the above states, You need some presets and loaders to transpile
es2015 or JSX files.
이와 비슷한 답변! – AuthorProxy