美文网首页
ES6探索1

ES6探索1

作者: cajan2 | 来源:发表于2016-08-14 06:58 被阅读30次

    ECMAScript 6 入门

    备忘录:

    windows下面的nvmw和nvm

    windows支持的不好了(nvmw无法安装node,后来发现目录结构已经变化了)
    还是果断使用ubuntu吧。

    几个node不同版本对es6的支持程度

    使用es-checker的结果

    • node v4.4.7
      nvm install 4
      Passes 29 feature Detections
      Your runtime supports 69% of ECMAScript 6

    • node v6.3.1
      nvm install 6
      Passes 37 feature Detections
      Your runtime supports 88% of ECMAScript 6

    • node 7没有正式版本,所以nvm无法安装
      注意:

    • nvm install node这条命令已经不支持了

    • 为了加速使用了cnpm
      但是cnpm连babel-cli都安装不了
      最后还是使用npm安装的
      在 ~/.npmrc文件中修改为taobao registry

      registry = http://registry.npm.taobao.org
    

    项目测试

    mkdir testproject
    cd testproject
    npm init
    npm install webpack babel-cli  babel-preset-es2015 babel-preset-stage-3  babel-loader --save-dev
    npm install babel-core babel-polyfill --save
    

    vi .babelrc

    {
      "presets": ["es2015","stage-3"],
      "plugins": []
    }
    

    为了使用打包工具webpack,需要在在module添加loaders,参考
    Using Babel-How to use Babel with your tool of choice
    查看package.json

    {
      "name": "testproject",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "dependencies": {
        "babel-core": "^6.13.2",
        "babel-polyfill": "^6.13.0"
      },
      "devDependencies": {
        "babel-cli": "^6.11.4",
        "babel-loader": "^6.2.4",
        "babel-preset-es2015": "^6.13.2",
        "babel-preset-stage-3": "^6.11.0",
        "css-loader": "^0.23.1",
        "style-loader": "^0.13.1",
        "webpack": "^1.13.1"
      },
      "scripts": {
        "build": "babel src -d lib"
      },
      "author": "",
      "license": "ISC"
    }
    
    

    查看webpack.config.js

    module: {
      loaders: [
        { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" }
      ]
    }
    

    相关文章

      网友评论

          本文标题:ES6探索1

          本文链接:https://www.haomeiwen.com/subject/rydysttx.html