Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup #5

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 55 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
let keepModules = false // false by default

// import presets
import presetEnv from "@babel/preset-env"
import presetReact from "@babel/preset-react"
import presetFlow from "@babel/preset-flow"

// import plugins
import pluginProposalFunctionBind from "@babel/plugin-proposal-function-bind"

import pluginProposalExportDefaultFrom from "@babel/plugin-proposal-export-default-from"
import pluginProposalLogicalAssignmentOperator from "@babel/plugin-proposal-logical-assignment-operators"
import pluginProposalOptionalChaining from "@babel/plugin-proposal-optional-chaining"
import pluginProposalPipelineOperator from "@babel/plugin-proposal-pipeline-operator"
import pluginProposalCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator"
import pluginProposalDoExpressions from "@babel/plugin-proposal-do-expressions"

import pluginProposalDecorators from "@babel/plugin-proposal-decorators"
import pluginProposalFunctionSent from "@babel/plugin-proposal-function-sent"
import pluginProposalExportNameSpaceFrom from "@babel/plugin-proposal-export-namespace-from"
import pluginProposalNumericSeperator from "@babel/plugin-proposal-numeric-separator"
import pluginProposalThrowExpressions from "@babel/plugin-proposal-throw-expressions"

import pluginProposalImportMeta from "@babel/plugin-syntax-import-meta"
import pluginProposalClassProperties from "@babel/plugin-proposal-class-properties"
import pluginProposalJSONStrings from "@babel/plugin-proposal-json-strings"

// module tranformer
import pluginTransformModulesCommonJS from "@babel/plugin-transform-modules-commonjs"
import pluginSyntaxDynamicImport from "@babel/plugin-syntax-dynamic-import"
import pluginAddModuleExports from "babel-plugin-add-module-exports"


if (process.env.BABEL_ENV === "production") {
keepModules = true
console.warn("setting `BABEL_ENV` to `production` for bypassing ES6 module transformming is deprecated. Use BABEL_KEEP_MODULES=\"true\" instead.")
Expand All @@ -15,46 +46,46 @@ if (process.env.BABEL_KEEP_MODULES === "true") {

let presets = [
[
require("@babel/preset-env"),
presetEnv,
{
targets: {
electron: 5,
},
modules: keepModules ? "false" : "commonjs"
},
],
require("@babel/preset-react"),
require("@babel/preset-flow"),
presetReact,
presetFlow
];

let plugins = [
require("@babel/plugin-proposal-function-bind"),

require("@babel/plugin-proposal-export-default-from"),
require("@babel/plugin-proposal-logical-assignment-operators"),
[require("@babel/plugin-proposal-optional-chaining"), { loose: false }],
[require("@babel/plugin-proposal-pipeline-operator"), { proposal: "minimal" }],
[require("@babel/plugin-proposal-nullish-coalescing-operator"), { loose: false }],
require("@babel/plugin-proposal-do-expressions"),

[require("@babel/plugin-proposal-decorators"), { legacy: true }],
require("@babel/plugin-proposal-function-sent"),
require("@babel/plugin-proposal-export-namespace-from"),
require("@babel/plugin-proposal-numeric-separator"),
require("@babel/plugin-proposal-throw-expressions"),

require("@babel/plugin-syntax-import-meta"),
[require("@babel/plugin-proposal-class-properties"), { loose: true }],
require("@babel/plugin-proposal-json-strings"),
pluginProposalFunctionBind,

pluginProposalExportDefaultFrom,
pluginProposalLogicalAssignmentOperator,
[pluginProposalOptionalChaining, { loose: false }],
[pluginProposalPipelineOperator, { proposal: "minimal" }],
[pluginProposalCoalescingOperator, { loose: false }],
pluginProposalDoExpressions,

[pluginProposalDecorators, { legacy: true }],
pluginProposalFunctionSent,
pluginProposalExportNameSpaceFrom,
pluginProposalNumericSeperator,
pluginProposalThrowExpressions,

pluginProposalImportMeta,
[pluginProposalClassProperties, { loose: true }],
pluginProposalJSONStrings,
];


// transform modules (e.g when without Rollup)
if (!keepModules) {
plugins.push(...[
require("@babel/plugin-transform-modules-commonjs"),
require("@babel/plugin-syntax-dynamic-import"),
require("babel-plugin-add-module-exports", {addDefaultProperty: false}) // atom needs this
pluginTransformModulesCommonJS,
pluginSyntaxDynamicImport,
[pluginAddModuleExports, {addDefaultProperty: false}] // atom needs this
]);
}

Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"repository": "https://github.com/atom-ide-community/babel",
"license": "MIT",
"scripts": {
"clean": "shx rm -rf dist",
"dev": "npm run clean && cross-env NODE_ENV=development cross-env BABEL_ENV=production rollup -c -w",
"build": "npm run clean && cross-env NODE_ENV=production cross-env BABEL_ENV=production rollup -c ",
"prepare": "npm run build",
"bump": "ncu -u"
},
"dependencies": {
Expand All @@ -22,26 +26,30 @@
"@babel/plugin-proposal-function-bind": "7.10.5",
"@babel/plugin-proposal-function-sent": "7.10.4",
"@babel/plugin-proposal-json-strings": "7.10.4",
"@babel/plugin-proposal-logical-assignment-operators": "7.10.4",
"@babel/plugin-proposal-logical-assignment-operators": "7.11.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.10.4",
"@babel/plugin-proposal-numeric-separator": "7.10.4",
"@babel/plugin-proposal-optional-chaining": "7.10.4",
"@babel/plugin-proposal-optional-chaining": "7.11.0",
"@babel/plugin-proposal-pipeline-operator": "7.10.5",
"@babel/plugin-proposal-throw-expressions": "7.10.4",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-import-meta": "7.10.4",
"@babel/preset-env": "7.10.4",
"@babel/preset-env": "7.11.0",
"@babel/preset-flow": "7.10.4",
"@babel/preset-react": "7.10.4",
"babel-plugin-add-module-exports": "^1.0.2"
},
"peerDependencies": {
"@babel/cli": "7.10.5",
"@babel/core": "7.10.5"
"@babel/core": "7.11.1"
},
"devDependencies": {
"@babel/cli": "7.10.5",
"@babel/core": "7.10.5",
"npm-check-updates": "7.0.2"
"@babel/core": "7.11.1",
"npm-check-updates": "7.0.2",
"rollup": "^2.23.0",
"rollup-plugin-atomic": "^1.2.0",
"shx": "^0.3.2",
"cross-env": "^7.0.2"
}
}
Loading