Giter Site home page Giter Site logo

babeldemo's Introduction

BabelDemo

Babel使用

1.Babel 是⼀个JavaScript编译器,它使⽤⾮常⼴泛,可以将es6转换成es5,从⽽在⼀些不⽀持es6的 浏览器中运⾏,这意味着你写es6代码的时候就不需要去关⼼浏览器是否⽀持es6

3.初始化项目npm init -y

4.安装babel-cli,运行npm install babel-cli --save-dev.babel-cli是命令⾏⼯具,安装以后我们就可以在命令⾏中通过babel命令来转码

5.为了测试babel,新建index.js

()	=>	console.log("hello world")
//npm install babel-plugin-transform-es2015-arrow-functions --save-dev 

class demo{}
//npm install babel-plugin-transform-es2015-classes --save-dev 

//npm install babel-preset-es2015 --save-dev
//npm install babel-preset-env --save-dev

6.可以通过./node_modules/.bin/babel index.js运行index.js或者修改package.json文件,运行npm run build

{
  "name": "babel-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "node_modules/.bin/babel index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
    "babel-plugin-transform-es2015-classes": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1"
  }
}

7.babel安装插件.运行npm install babel-preset-env --save-dev,新建.babelrc文件

{
	"presets":["env"]
}

8.运行npm run build

babeldemo's People

Contributors

yanfeng12 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.