“Babel, Babel Nodejs, Config Babel,” Kode Jawaban

Konfigurasikan Babel untuk Node

@babel/core: A fundamental package to run any babel setup/configuration.
@babel/cli:A built-in CLI which can be used to compile files from the command line/terminal.
@babel/node:is a CLI that works the same as the Node.js CLI, with the added benefit of compiling with Babel presets and plugins before running it.
@babel/preset-env(dev): is a smart preset that allows you to use the latest JavaScript .
@babel/plugin-transform-runtime(dev):A plugin that enables the re-use of Babel's injected helper code to save on code size.
@babel/runtime(save): a package to be installed production dependency to avoid duplication across your compiled output.
  
// yarn add 
@babel/node @babel/preset-env @babel/plugin-transform-runtime @babel/runtime
    
// .babelrc
{
  "presets": ["@babel/preset-env"],
  "plugins": [
    ["@babel/plugin-transform-runtime"]
  ]
}

// package.json
"scripts": {
    "start": "npm run build && node ./build/src/server.js",
    "dev": "nodemon --exec babel-node ./src/server.js",
    "clean": "rm -rf build && mkdir build",
    "build-babel": "babel ./src -d ./build/src",
    "build": "npm run clean && npm run build-babel"
}
minh chiu

Babel, Babel Nodejs, Config Babel,

// yarn add @babel/cli @babel/core @babel/node @babel/plugin-transform-runtime @babel/preset-env --dev
// yarn add @babel/runtime 
"dependencies": {
    "@babel/runtime": "^7.15.4" //a package to be installed production dependency to avoid duplication across your compiled output.
  },
  "devDependencies": {
    "@babel/cli": "^7.15.7", // A built-in CLI which can be used to compile files from the command line/terminal.
    "@babel/core": "^7.15.5", // a fundamental package to run any babel setup/configuration
    "@babel/node": "^7.15.4", //babel-node is a CLI that works the same as the Node.js CLI, with the added benefit of compiling with Babel presets and plugins before running it.
    "@babel/plugin-transform-runtime": "^7.15.0", // A plugin that enables the re-use of Babel's injected helper code to save on code size.
    "@babel/preset-env": "^7.15.6" //  is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s).
  }

// package.json
"scripts": {
    "start": "yarn run build && node ./build/src/index.js",
    "start:dev": "/node_modules/.bin/babel-node ./src/index.js",
    "clean": "rm -rf build && mkdir build",
    "build-babel": "babel ./src -d ./build/src",
    "build": "yarn run clean && yarn run build-babel"
  }

// .babelrc
{
  "presets": ["@babel/preset-env"],
  "plugins": [
    ["@babel/plugin-transform-runtime"]
  ]
}

minhchiu

Jawaban yang mirip dengan “Babel, Babel Nodejs, Config Babel,”

Pertanyaan yang mirip dengan “Babel, Babel Nodejs, Config Babel,”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya