From 9afb0463ca4a0ba836c61f0222f4164d0f01a81f Mon Sep 17 00:00:00 2001 From: bplok20010 Date: Sat, 10 Oct 2020 22:56:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4strictMode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++------ lib/index.js | 1 + lib/plugins.js | 34 ++++++++++++++++++---------------- package.json | 6 +----- src/index.js | 3 ++- src/plugins.js | 32 ++++++++++++++++---------------- 6 files changed, 42 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 0b8476c..b8d76d8 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,6 @@ Setting this to `false` will not transform modules. Also note that `cjs` is just an alias for `commonjs`. -### `strictMode` - -`boolean`, defaults to `true` - -详细: [babel-preset-env](https://babeljs.io/docs/en/babel-preset-env) - ### `runtimeOptions` `object` @@ -51,3 +45,7 @@ absoluteRuntime: false, ### decoratorsBeforeExport `boolean`, defaults to `true` + +--- + +注:如果需要关闭`strictMode`,可参考: https://babeljs.io/docs/en/babel-plugin-transform-strict-mode diff --git a/lib/index.js b/lib/index.js index ad4386a..2fda076 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10,6 +10,7 @@ var _plugins = _interopRequireDefault(require("./plugins")); module.exports = function (api, opts) { var defaultOpts = { modules: "commonjs", + // 无效 strictMode: true, // useFlow: false, decoratorsBeforeExport: true, diff --git a/lib/plugins.js b/lib/plugins.js index 768655b..461efc6 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -7,21 +7,22 @@ Object.defineProperty(exports, "__esModule", { exports.default = _default; function _default(api, opts) { - var modules = opts.modules, - strictMode = opts.strictMode, - runtimeOptions = opts.runtimeOptions, + var runtimeOptions = opts.runtimeOptions, _opts$decoratorsBefor = opts.decoratorsBeforeExport, - decoratorsBeforeExport = _opts$decoratorsBefor === void 0 ? true : _opts$decoratorsBefor; - var modulesMap = { - commonjs: require.resolve("@babel/plugin-transform-modules-commonjs"), - cjs: require.resolve("@babel/plugin-transform-modules-commonjs"), - umd: require.resolve("@babel/plugin-transform-modules-umd"), - amd: require.resolve("@babel/plugin-transform-modules-amd"), - systemjs: require.resolve("@babel/plugin-transform-modules-systemjs") - }; - var modulePlugin = strictMode && modulesMap[modules] && [modulesMap[modules], { - strictMode - }]; // class-properties 开启 `loose` 后 private-methods 也要同时开启 + decoratorsBeforeExport = _opts$decoratorsBefor === void 0 ? true : _opts$decoratorsBefor; // const modulesMap = { + // commonjs: require.resolve("@babel/plugin-transform-modules-commonjs"), + // cjs: require.resolve("@babel/plugin-transform-modules-commonjs"), + // umd: require.resolve("@babel/plugin-transform-modules-umd"), + // amd: require.resolve("@babel/plugin-transform-modules-amd"), + // systemjs: require.resolve("@babel/plugin-transform-modules-systemjs"), + // }; + // const modulePlugin = strictMode && modulesMap[modules] && [ + // modulesMap[modules], + // { + // strictMode, + // }, + // ]; + // class-properties 开启 `loose` 后 private-methods 也要同时开启 return [// useFlow && [ // require.resolve("@babel/plugin-transform-flow-strip-types"), @@ -51,6 +52,7 @@ function _default(api, opts) { useBuiltIns: true }], require.resolve("@babel/plugin-syntax-top-level-await"), // require.resolve("@babel/plugin-transform-react-jsx"), // require.resolve("@babel/plugin-transform-proto-to-assign"), //Internet Explorer(10 and below) - runtimeOptions && [require.resolve("@babel/plugin-transform-runtime"), runtimeOptions], require.resolve("babel-plugin-dev-expression"), //Replaces __DEV__ with process.env.NODE_ENV !== 'production' - modulePlugin].filter(Boolean); + runtimeOptions && [require.resolve("@babel/plugin-transform-runtime"), runtimeOptions], require.resolve("babel-plugin-dev-expression") //Replaces __DEV__ with process.env.NODE_ENV !== 'production' + // modulePlugin, + ].filter(Boolean); } \ No newline at end of file diff --git a/package.json b/package.json index e6cf049..ffdecde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-packez", - "version": "1.1.1", + "version": "1.2.0", "description": "", "main": "./lib/index.js", "scripts": { @@ -46,10 +46,6 @@ "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-top-level-await": "^7.10.1", "@babel/plugin-transform-destructuring": "^7.10.1", - "@babel/plugin-transform-modules-amd": "^7.10.1", - "@babel/plugin-transform-modules-commonjs": "^7.10.1", - "@babel/plugin-transform-modules-systemjs": "^7.10.1", - "@babel/plugin-transform-modules-umd": "^7.10.1", "@babel/plugin-transform-proto-to-assign": "^7.10.1", "@babel/plugin-transform-runtime": "^7.10.1", "@babel/preset-env": "^7.10.2", diff --git a/src/index.js b/src/index.js index 929fd44..81fa9cf 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,8 @@ import plugins from "./plugins"; module.exports = function(api, opts) { const defaultOpts = { - modules: "commonjs", + modules: "commonjs", + // 无效 strictMode: true, // useFlow: false, decoratorsBeforeExport: true, diff --git a/src/plugins.js b/src/plugins.js index 1bf6daf..26ac6c3 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,25 +1,25 @@ export default function (api, opts) { const { - modules, - strictMode, + // modules, + // strictMode, runtimeOptions, // useFlow = true, decoratorsBeforeExport = true, } = opts; - const modulesMap = { - commonjs: require.resolve("@babel/plugin-transform-modules-commonjs"), - cjs: require.resolve("@babel/plugin-transform-modules-commonjs"), - umd: require.resolve("@babel/plugin-transform-modules-umd"), - amd: require.resolve("@babel/plugin-transform-modules-amd"), - systemjs: require.resolve("@babel/plugin-transform-modules-systemjs"), - }; - const modulePlugin = strictMode && modulesMap[modules] && [ - modulesMap[modules], - { - strictMode, - }, - ]; + // const modulesMap = { + // commonjs: require.resolve("@babel/plugin-transform-modules-commonjs"), + // cjs: require.resolve("@babel/plugin-transform-modules-commonjs"), + // umd: require.resolve("@babel/plugin-transform-modules-umd"), + // amd: require.resolve("@babel/plugin-transform-modules-amd"), + // systemjs: require.resolve("@babel/plugin-transform-modules-systemjs"), + // }; + // const modulePlugin = strictMode && modulesMap[modules] && [ + // modulesMap[modules], + // { + // strictMode, + // }, + // ]; // class-properties 开启 `loose` 后 private-methods 也要同时开启 return [ // useFlow && [ @@ -99,6 +99,6 @@ export default function (api, opts) { runtimeOptions, ], require.resolve("babel-plugin-dev-expression"), //Replaces __DEV__ with process.env.NODE_ENV !== 'production' - modulePlugin, + // modulePlugin, ].filter(Boolean); }