Strict mode transform

This plugin places a "use strict"; directive at the top of all files to enable strict mode

该插件可以通过 babel-plugin-transform-es2015-modules-commonjs 来启用。 如果你想禁用它,你可以关闭 strict 或者在 commonjs 转换中添加 strictMode: false 选项。

示例

输入

foo();

输出

"use strict";

foo();

安装

npm install --save-dev babel-plugin-transform-strict-mode

使用

通过 .babelrc(推荐)

.babelrc

未包含选项:

{
  "plugins": ["transform-strict-mode"]
}

包含选项:

{
  "plugins": [
    ["transform-strict-mode", {
      "strict": true
    }]
  ]
}

通过 CLI

babel --plugins transform-strict-mode script.js

通过 Node API

require("babel-core").transform("code", {
  plugins: ["transform-strict-mode"]
});