From 18453d113eb9ba1aa72991a227d6ac68ec38c849 Mon Sep 17 00:00:00 2001 From: maoznir Date: Wed, 24 Feb 2021 15:17:21 +0200 Subject: [PATCH] Refactor build to use microbundle instead of webpack --- bundlewatch.config.js | 2 +- package.json | 19 ++-- tools/update_version | 199 ------------------------------------------ webpack.config.js | 30 ------- 4 files changed, 12 insertions(+), 238 deletions(-) delete mode 100755 tools/update_version delete mode 100644 webpack.config.js diff --git a/bundlewatch.config.js b/bundlewatch.config.js index 883b563..6c39fa2 100644 --- a/bundlewatch.config.js +++ b/bundlewatch.config.js @@ -2,7 +2,7 @@ const bundlewatchConfig = { files: [ { path: './dist/cloudinary-react.js', - maxSize: '44.5kb' + maxSize: '8kb' } ], defaultCompression: 'gzip', diff --git a/package.json b/package.json index 327e1cf..21d7af7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,13 @@ "name": "cloudinary-react", "version": "1.6.8", "description": "Present Cloudinary images and videos using React components", - "main": "lib/index.js", + "main": "./dist/cloudinary-react.js", + "umd:main": "./dist/cloudinary-react.umd.js", + "module": "dist/cloudinary-react.esm.js", + "source": "src/index.js", + "engines": { + "node": ">=10" + }, "scripts": { "test": "run-s build test:unit test:build test:e2e", "test:unit": "jest", @@ -10,8 +16,8 @@ "test:e2e": "cd ./e2e-test && npm run test", "test:coverage": "jest --coverage", "pretest:e2e": "npm pack && cpy cloudinary-react-*.tgz e2e-test --rename=cloudinary-react.tgz", - "prebuild": "node_modules/.bin/babel src --out-dir lib --copy-files ", - "build": "node_modules/.bin/webpack && npm run bundlewatch", + "build": "microbundle --no-compress --sourcemap false --jsx React.createElement --format esm,umd,cjs && npm run bundlewatch", + "start": "microbundle watch --no-compress --sourcemap false --jsx React.createElement --format esm,umd,cjs", "bundlewatch": "bundlewatch --config ./bundlewatch.config.js", "storybook": "start-storybook -p 6006", "build-storybook": "del-cli docs && build-storybook -c .storybook -o docs", @@ -53,11 +59,10 @@ "jest-enzyme": "^7.1.2", "jest-extended": "^0.11.5", "jsdom": "^11.12.0", + "microbundle": "^0.13.0", "npm-run-all": "^4.1.5", "react": "^16.3.3", - "react-dom": "^16.3.3", - "webpack": "4.27.1", - "webpack-cli": "^3.1.2" + "react-dom": "^16.3.3" }, "dependencies": { "cloudinary-core": "^2.11.3", @@ -67,8 +72,6 @@ "react": "^16.3.3 || ^17.0.0" }, "files": [ - "src", - "lib", "dist" ] } diff --git a/tools/update_version b/tools/update_version deleted file mode 100755 index bfc8ecb..0000000 --- a/tools/update_version +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/env bash - -# Update version number and prepare for publishing the new version - -set -e - -# Empty to run the rest of the line and "echo" for a dry run -CMD_PREFIX= - -# Add a quote if this is a dry run -QUOTE= - -NEW_VERSION= - -function echo_err -{ - echo "$@" 1>&2; -} - -function usage -{ - echo "Usage: $0 [parameters]" - echo " -v | --version set a new version" - echo " -c | --current show current version" - echo " -d | --dry-run print the commands without executing them" - echo " -h | --help print this information and exit" - echo - echo "For example: $0 -v 1.2.3" -} - -function process_arguments -{ - while [ "$1" != "" ]; do - case $1 in - -v | --version ) - shift - NEW_VERSION=${1:-} - if ! [[ "${NEW_VERSION}" =~ [0-9]+\.[0-9]+\.[0-9]+(\-.+)? ]]; then - echo_err "You must supply a new version after -v or --version" - echo_err "For example:" - echo_err " 1.2.3" - echo_err " 1.2.3-rc1" - echo_err "" - usage; return 1 - fi - ;; - -c | --current ) - echo `current_version` - exit - ;; - -d | --dry-run ) - CMD_PREFIX=echo - echo "Dry Run" - echo "" - ;; - -h | --help ) - usage; return 0 - ;; - * ) - usage; return 1 - esac - shift || true - done -} - -# Intentionally make pushd silent -function pushd -{ - command pushd "$@" > /dev/null -} - -# Intentionally make popd silent -function popd -{ - command popd "$@" > /dev/null -} - -# Check if one version is less than or equal than other -# Example: -# ver_lte 1.2.3 1.2.3 && echo "yes" || echo "no" # yes -# ver_lte 1.2.3 1.2.4 && echo "yes" || echo "no" # yes -# ver_lte 1.2.4 1.2.3 && echo "yes" || echo "no" # no -function ver_lte -{ - [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] -} - -# Extract the last entry or entry for a given version -# The function is not currently used in this file. -# Examples: -# changelog_last_entry -# changelog_last_entry 1.10.0 -# -function changelog_last_entry -{ - sed -e "1,/^${1}/d" -e '/^=/d' -e '/^$/d' -e '/^[0-9]/,$d' CHANGELOG.md -} - -function verify_dependencies -{ - # Test if the gnu grep is installed - if ! grep --version | grep -q GNU - then - echo_err "GNU grep is required for this script" - echo_err "You can install it using the following command:" - echo_err "" - echo_err "brew install grep --with-default-names" - return 1 - fi - - if [[ -z "$(type -t git-changelog)" ]] - then - echo_err "git-extras packages is not installed." - echo_err "You can install it using the following command:" - echo_err "" - echo_err "brew install git-extras" - return 1 - fi -} - -# Replace old string only if it is present in the file, otherwise return 1 -function safe_replace -{ - local old=$1 - local new=$2 - local file=$3 - - grep -q "${old}" "${file}" || { echo_err "${old} was not found in ${file}"; return 1; } - - ${CMD_PREFIX} sed -E -i '.bak' "${QUOTE}s/${old}/${new}/${QUOTE}" "${file}" -} - -function current_version -{ - grep -oiP '(?<=version": ")([0-9.]+)(?=")' package.json -} - -function update_version -{ - if [ -z "${NEW_VERSION}" ]; then - usage; return 1 - fi - - # Enter git root - pushd $(git rev-parse --show-toplevel) - local current_version=$(current_version) - - if [ -z "${current_version}" ]; then - echo_err "Failed getting current version, please check directory structure and/or contact developer" - return 1 - fi - - # Use literal dot character in regular expression - local current_version_re=${current_version//./\\.} - - echo "# Current version is: ${current_version}" - echo "# New version is: ${NEW_VERSION}" - - ver_lte "${NEW_VERSION}" "${current_version}" && { echo_err "New version is not greater than current version"; return 1; } - - # Add a quote if this is a dry run - QUOTE=${CMD_PREFIX:+"'"} - - npm version --no-git-tag-version "${NEW_VERSION}" - - ${CMD_PREFIX} git changelog -t ${NEW_VERSION} || true - - echo "" - echo "# After editing CHANGELOG.md, optionally review changes and issue these commands:" - echo git add package.json CHANGELOG.md - echo git commit -m \"Version ${NEW_VERSION}\" - echo sed -e "'1,/^${NEW_VERSION//./\\.}/d'" \ - -e "'/^=/d'" \ - -e "'/^$/d'" \ - -e "'/^[0-9]/,\$d'" \ - CHANGELOG.md \ - \| git tag -a "'${NEW_VERSION}'" --file=- - - # Don't run those commands on dry run - [ -n "${CMD_PREFIX}" ] && { popd; return 0; } - - echo "" - read -p "Run the above commands automatically? (y/N): " confirm && [[ ${confirm} == [yY] || ${confirm} == [yY][eE][sS] ]] || { popd; return 0; } - - git add package.json CHANGELOG.md - git commit -m "Version ${NEW_VERSION}" - sed -e "1,/^${NEW_VERSION//./\\.}/d" \ - -e "/^=/d" \ - -e "/^$/d" \ - -e "/^[0-9]/,\$d" \ - CHANGELOG.md \ - | git tag -a "${NEW_VERSION}" --file=- - - popd -} - -verify_dependencies -process_arguments $* -update_version diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 26fcfad..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,30 +0,0 @@ -const { resolve } = require("path"); - -module.exports = { - entry: './src/index.js', - mode: 'production', - output: { - path: resolve(process.cwd(), 'dist'), - filename: 'cloudinary-react.js', - library: 'cloudinaryReact', - libraryTarget: 'umd', - umdNamedDefine: true - }, - module: { - rules: [ - { - test: /\.js$/, - exclude: /node_modules/, - loader: 'babel-loader', - options: { - rootMode: "upward", - } - } - ] - - }, - externals: { - "React": "react", - "cloudinary": "cloudinary-core" - } -}; \ No newline at end of file