Giter VIP home page Giter VIP logo

recoil-transform-with-babel's Introduction

Babel转义Recoil

尝试使用babel转义recoil,使得recoil兼容IE版本

webpack 配置

编译js文件时,使用include手动指定编译范围。

  • srcDir
  • recoil
module.exports = {
  module: {
    rules: [
      {
        test: /\.js/,
        loader: 'babel-loader',
        include: [srcDir, path.resolve(__dirname, '../node_modules/recoil')]
      }
    ]
  }
}

babel.config.json

安装babel基础依赖 babel-loader@babel/core.

  npm install babel-loader @babel/core -D

配置 presets @babel/preset-env@babel/preset-react

由于recoil采用了ES6+语法,所以需要设置polyfill进行兼容处理。

方案一

babel.config.json

  {
    "presets": [
      [
        "@babel/preset-env", 
        {
          "useBuiltIns": "entry",
          "corejs": {
            "version": "3",
            "proposals": true
          },
          "targets": {
            "chrome": 75,
            "ie": 10
          }
        }
      ],
      ["@babel/preset-react"]
    ],
    "plugins": [
      [
        "@babel/plugin-transform-runtime", 
        {
          "corejs": false,
          "proposals": true
        }
      ]
    ]
  }

index.js

  import 'core-js-pure/stable';
  import 'regenerator-runtime/runtime';

编译

执行 npm run build,运行dist/index.html选择 IE11打开。

运行结果,IE11报错.

  module.exports = require("regenerator-runtime");

recoil-transform-with-babel's People

Contributors

kelh93 avatar

Stargazers

Roman avatar travis avatar

Watchers

travis avatar  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.