From 44802f47f7576f236d46af88a2303bf091880619 Mon Sep 17 00:00:00 2001 From: Nicola Molinari Date: Wed, 25 Nov 2020 21:06:32 +0100 Subject: [PATCH] fix: keep babel build for CJS packages --- package.json | 8 +--- packages/create-mc-app/package.json | 3 -- packages/mc-html-template/package.json | 37 +++++++++++++++++-- .../create-webpack-config-for-development.js | 5 +-- .../create-webpack-config-for-production.js | 5 +-- .../mc-scripts/config/vendors-to-transpile.js | 5 +-- packages/mc-scripts/package.json | 37 +++++++++++++++++-- packages/mc-scripts/src/index.js | 2 + playground/.env | 1 + 9 files changed, 76 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 0d577fb37b..2a6ca22dc4 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,8 @@ "template-starter:build": "yarn --cwd application-templates/starter build", "template-starter:start": "yarn --cwd application-templates/starter start", "template-starter:start:prod:local": "yarn --cwd application-templates/starter start:prod:local", - "prebuild": "lerna run prebuild --no-private", - "build": "preconstruct build && yarn workspace @commercetools-frontend/application-shell run build", - "build:watch": "preconstruct watch & yarn workspace @commercetools-frontend/application-shell run build:bundles:watch", + "build": "preconstruct build && NODE_ENV=production lerna run build --no-private", + "build:watch": "preconstruct watch & NODE_ENV=development lerna run --no-private --parallel build:bundles:watch", "build:website": "yarn build && yarn --cwd website build && yarn --cwd website-components-playground build", "now-build": "yarn build:website && rm -rf public && mv website/public public", "labels:sync": "github-labels sync", @@ -76,11 +75,8 @@ "packages/application-shell-connectors", "packages/browser-history", "packages/constants", - "packages/create-mc-app", "packages/i18n", "packages/l10n", - "packages/mc-html-template", - "packages/mc-scripts", "packages/notifications", "packages/permissions", "packages/react-notifications", diff --git a/packages/create-mc-app/package.json b/packages/create-mc-app/package.json index bd364bff4f..64bfa40d8e 100644 --- a/packages/create-mc-app/package.json +++ b/packages/create-mc-app/package.json @@ -15,9 +15,6 @@ "publishConfig": { "access": "public" }, - "main": "dist/commercetools-frontend-create-mc-app.cjs.js", - "module": "dist/commercetools-frontend-create-mc-app.esm.js", - "files": ["bin", "dist", "package.json", "LICENSE", "README.md"], "bin": { "create-mc-app": "./bin/create-mc-app.js" }, diff --git a/packages/mc-html-template/package.json b/packages/mc-html-template/package.json index 931e76a596..273b0db87a 100644 --- a/packages/mc-html-template/package.json +++ b/packages/mc-html-template/package.json @@ -15,10 +15,9 @@ "publishConfig": { "access": "public" }, - "main": "dist/commercetools-frontend-mc-html-template.cjs.js", - "module": "dist/commercetools-frontend-mc-html-template.esm.js", + "main": "./build/index.js", "files": [ - "dist", + "build", "html-scripts", "html-styles", "webpack.js", @@ -26,6 +25,11 @@ "LICENSE", "README.md" ], + "scripts": { + "prebuild": "rimraf build/**", + "build": "babel src --out-dir build", + "build:bundles:watch": "yarn build -w" + }, "dependencies": { "@babel/runtime": "7.12.5", "@babel/runtime-corejs3": "7.12.5", @@ -35,8 +39,35 @@ "uglify-es": "3.3.9", "uglifycss": "0.0.29" }, + "devDependencies": { + "@babel/plugin-transform-runtime": "7.12.1", + "@babel/preset-env": "7.12.7" + }, "engines": { "node": ">=10", "npm": ">=5" + }, + "babel": { + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "10" + }, + "modules": "commonjs", + "useBuiltIns": "usage", + "corejs": 3 + } + ] + ], + "plugins": [ + [ + "@babel/plugin-transform-runtime", + { + "corejs": 3 + } + ] + ] } } diff --git a/packages/mc-scripts/config/create-webpack-config-for-development.js b/packages/mc-scripts/config/create-webpack-config-for-development.js index c67b68b052..e7fed82a27 100644 --- a/packages/mc-scripts/config/create-webpack-config-for-development.js +++ b/packages/mc-scripts/config/create-webpack-config-for-development.js @@ -1,5 +1,2 @@ // For backwards compatibilty -const { - createWebpackConfigForDevelopment, -} = require('../dist/commercetools-frontend-mc-scripts.cjs'); -module.exports = createWebpackConfigForDevelopment; +module.exports = require('../build/config/create-webpack-config-for-development'); diff --git a/packages/mc-scripts/config/create-webpack-config-for-production.js b/packages/mc-scripts/config/create-webpack-config-for-production.js index 7e90df212e..a3b15bc346 100644 --- a/packages/mc-scripts/config/create-webpack-config-for-production.js +++ b/packages/mc-scripts/config/create-webpack-config-for-production.js @@ -1,5 +1,2 @@ // For backwards compatibilty -const { - createWebpackConfigForProduction, -} = require('../dist/commercetools-frontend-mc-scripts.cjs'); -module.exports = createWebpackConfigForProduction; +module.exports = require('../build/config/create-webpack-config-for-production'); diff --git a/packages/mc-scripts/config/vendors-to-transpile.js b/packages/mc-scripts/config/vendors-to-transpile.js index b2e6e3e5f9..2d95f82eee 100644 --- a/packages/mc-scripts/config/vendors-to-transpile.js +++ b/packages/mc-scripts/config/vendors-to-transpile.js @@ -1,5 +1,2 @@ // For backwards compatibilty -const { - vendorsToCompile, -} = require('../dist/commercetools-frontend-mc-scripts.cjs'); -module.exports = vendorsToCompile; +module.exports = require('../build/config/vendors-to-transpile'); diff --git a/packages/mc-scripts/package.json b/packages/mc-scripts/package.json index 44915414f7..1d0b4bcf0f 100644 --- a/packages/mc-scripts/package.json +++ b/packages/mc-scripts/package.json @@ -15,9 +15,8 @@ "publishConfig": { "access": "public" }, - "main": "dist/commercetools-frontend-mc-scripts.cjs.js", - "module": "dist/commercetools-frontend-mc-scripts.esm.js", - "files": ["bin", "dist", "config", "package.json", "LICENSE", "README.md"], + "main": "./build/index.js", + "files": ["bin", "build", "config", "package.json", "LICENSE", "README.md"], "bin": { "mc-scripts": "./bin/mc-scripts.js" }, @@ -25,6 +24,11 @@ "production": [">1%", "not op_mini all", "not dead"], "development": ["last 2 firefox versions", "last 2 chrome versions"] }, + "scripts": { + "prebuild": "rimraf build/**", + "build": "babel src --out-dir build", + "build:bundles:watch": "yarn build -w" + }, "dependencies": { "@babel/runtime": "7.12.5", "@babel/runtime-corejs3": "7.12.5", @@ -74,8 +78,35 @@ "webpack-dev-server": "3.11.0", "webpackbar": "4.0.0" }, + "devDependencies": { + "@babel/plugin-transform-runtime": "7.12.1", + "@babel/preset-env": "7.12.7" + }, "engines": { "node": ">=10", "npm": ">=5" + }, + "babel": { + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "10" + }, + "modules": "commonjs", + "useBuiltIns": "usage", + "corejs": 3 + } + ] + ], + "plugins": [ + [ + "@babel/plugin-transform-runtime", + { + "corejs": 3 + } + ] + ] } } diff --git a/packages/mc-scripts/src/index.js b/packages/mc-scripts/src/index.js index d0b2a60a0a..54c8974b50 100644 --- a/packages/mc-scripts/src/index.js +++ b/packages/mc-scripts/src/index.js @@ -1,9 +1,11 @@ const createWebpackConfigForDevelopment = require('./config/create-webpack-config-for-development'); const createWebpackConfigForProduction = require('./config/create-webpack-config-for-production'); +const createDevServerConfig = require('./config/webpack-dev-server.config'); const vendorsToCompile = require('./config/vendors-to-transpile'); module.exports = { createWebpackConfigForDevelopment, createWebpackConfigForProduction, + createDevServerConfig, vendorsToCompile, }; diff --git a/playground/.env b/playground/.env index f7a692680a..6baacc27b5 100644 --- a/playground/.env +++ b/playground/.env @@ -1,6 +1,7 @@ CLOUD_IDENTIFIER="gcp-eu" APP_URL="https://" ECHO_SERVER_URL="http://localhost:3000/api/echo" +HOST_GCP_STAGING="" TRACKING_GTM="GTM-XXXXXX" ENABLE_NEW_JSX_TRANSFORM="true" FAST_REFRESH="true" \ No newline at end of file