From 1553f9ae6c40460ec52f9a4202f45400387a54a3 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Mon, 13 Jan 2020 14:36:53 -0800 Subject: [PATCH] transpile src to multi targets (#1492) --- packages/subapp-web/.babelrc.js | 20 +++++++++++++------- packages/subapp-web/.gitignore | 1 + packages/subapp-web/lib/index.js | 2 +- packages/subapp-web/package.json | 11 ++++++----- packages/subapp-web/xclap.js | 14 ++++++++++++-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/packages/subapp-web/.babelrc.js b/packages/subapp-web/.babelrc.js index f04ef4351..7ee45c618 100644 --- a/packages/subapp-web/.babelrc.js +++ b/packages/subapp-web/.babelrc.js @@ -1,7 +1,13 @@ -module.exports = { - presets: [ - ["@babel/env", { modules: "auto" }], - "@babel/react", - process.env.MINIFY ? "minify" : undefined - ].filter(x => x) -}; +const envOpts = { modules: "auto" }; + +if (process.env.BABEL_ENV === "src-node") { + Object.assign(envOpts, { targets: { node: "10" } }); +} + +const presets = [["@babel/env", envOpts], "@babel/react"]; + +if (process.env.MINIFY) { + presets.push("minify"); +} + +module.exports = { presets }; diff --git a/packages/subapp-web/.gitignore b/packages/subapp-web/.gitignore index 082f26b05..f8e2e7a9e 100644 --- a/packages/subapp-web/.gitignore +++ b/packages/subapp-web/.gitignore @@ -1,3 +1,4 @@ browser dist *-lock.* +node-dist diff --git a/packages/subapp-web/lib/index.js b/packages/subapp-web/lib/index.js index 1ac55289b..8cd33833b 100644 --- a/packages/subapp-web/lib/index.js +++ b/packages/subapp-web/lib/index.js @@ -4,7 +4,7 @@ const { registerSubApp } = require("subapp-util"); -const { default: makeSubAppSpec } = require("../browser/make-subapp-spec"); +const { default: makeSubAppSpec } = require("../node-dist/make-subapp-spec"); const { setupFramework } = require("./util"); diff --git a/packages/subapp-web/package.json b/packages/subapp-web/package.json index 110b816f7..7e3f5a9cc 100644 --- a/packages/subapp-web/package.json +++ b/packages/subapp-web/package.json @@ -5,10 +5,10 @@ "browser": "browser/index.js", "main": "lib/index.js", "scripts": { - "test": "clap check", - "coverage": "clap check", - "build": "clap -x -n compile minify", - "compile": "babel src -d browser --source-maps" + "test": "clap -x compile check", + "coverage": "clap -x compile check", + "build": "clap compile", + "prepublishOnly": "clap compile" }, "keywords": [ "web", @@ -23,7 +23,8 @@ "files": [ "lib", "browser", - "dist" + "dist", + "node-dist" ], "dependencies": { "history": "^4.9.0", diff --git a/packages/subapp-web/xclap.js b/packages/subapp-web/xclap.js index 09d7913a5..5e03e4bc1 100644 --- a/packages/subapp-web/xclap.js +++ b/packages/subapp-web/xclap.js @@ -1,7 +1,17 @@ const xclap = require("xclap"); +const { env, exec, concurrent } = xclap; + xclap.load({ - minify: xclap.exec("babel src -d dist --source-maps", { - execOptions: { env: { MINIFY: "true" } } + compile: concurrent("compile-browser", "compile-dist", "compile-node"), + "compile-browser": exec("babel src -d browser --delete-dir-on-start --source-maps", { + env: { BABEL_ENV: "src-browser" } + }), + "compile-dist": exec("babel src -d dist --delete-dir-on-start --source-maps", { + env: { MINIFY: "true", BABEL_ENV: "src-dist" } + }), + "compile-node": exec("babel src -d node-dist --delete-dir-on-start --source-maps", { + env: { BABEL_ENV: "src-node" } }) }); + require("electrode-archetype-njs-module-dev")();