跳至主要內容

@babel/plugin-transform-strict-mode

此外掛程式可透過 @babel/plugin-transform-modules-commonjs 啟用。如果你想停用它,你可以關閉 strict 或將 strictMode: false 作為選項傳遞給 commonjs 轉換。

範例

輸入

JavaScript
foo();

輸出

JavaScript
"use strict";

foo();

安裝

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

用法

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

透過 CLI

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

透過 Node API

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