跳至主内容

@babel/plugin-transform-strict-mode

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

该插件可通过 @babel/plugin-transform-modules-commonjs 启用。 如需禁用,可关闭 strict 选项,或在 commonjs 转换中传入 strictMode: false 参数。

示例

输入

JavaScript
foo();

输出

JavaScript
"use strict";

foo();

安装

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

用法

通过配置文件(推荐)

babel.config.json
{
"plugins": ["@babel/plugin-transform-strict-mode"]
}

通过命令行

Shell
babel --plugins @babel/plugin-transform-strict-mode script.js

通过 Node API

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