Babel预设阶段

时间:2019-07-09 12:43:12

标签: webpack babel babel-loader

我正在阅读babel文档中的舞台预设,我无法确定何时为什么使用诸如stage-2和stage-3之类的舞台预设。

package.json中具有以下配置:

"devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-loader": "7.0.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-2": "^6.24.1",
    "html-webpack-plugin": "^3.2.0",
    "strip-loader": "^0.1.2",
    "webpack": "4.29.6",
    "webpack-bundle-analyzer": "3.1.0",
    "webpack-cli": "3.3.0",
    "webpack-dev-server": "3.2.1"
  },
  "babel": {
    "presets": [
      "env",
      "stage-2"
    ]
}

Webpack配置:

module.exports = {
  entry: ["babel-polyfill", "./src/index"],
  output: {
    filename: "bundle.js"
  },
  plugins: [
    //Injects the bundle.js into the html
    new HtmlWebpackPlugin({
      template: "src/index.html"
    })
  ],
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ["babel-loader"]
      }
    ]
  }
};

索引

let var1 = () => {
  return 4;
};

function resolveAfter2Seconds(x) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

async function f1() {
  var x = await resolveAfter2Seconds(10);
  console.log(x); // 10
}

f1();

是否使用Stage-2并没有任何区别。解析过程执行良好。

0 个答案:

没有答案