Skip to content

Commit

Permalink
fix: modernize build using esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Oct 3, 2023
1 parent 3d47152 commit 094d6c6
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 24 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"test": "cross-env NODE_ENV=test ava",
"test:coverage": "cross-env NODE_ENV=test nyc ava",
"test:codecov": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"build:lib": "cross-env NODE_ENV=production babel src -d lib --ignore src/demo",
"build:lazy": "cross-env NODE_ENV=production LAZY=true babel src -d lazy --ignore src/demo",
"build:demo": "cross-env NODE_ENV=production webpack --config webpack/production.babel.js",
"build:dist": "cross-env NODE_ENV=production webpack --config webpack/dist.babel.js",
"build:standalone": "cross-env NODE_ENV=production webpack --config webpack/standalone.babel.js && node scripts/standalone-es6.js",
"build:es6": "rsync --exclude demo -r ./src/ ./es6/ && find ./es6/ -name '*.js' -exec grep -q 'import React' {} \\; -exec mv {} {}x \\;",
"build:lib": "node scripts/build src/*.js src/players/*.js --outdir=lib --format=cjs",
"build:lazy": "node scripts/build src/*.js src/players/*.js --outdir=lazy --format=cjs",
"build:dist": "node scripts/build src/index.js --outfile=dist/ReactPlayer.js --format=iife --bundle --minify --sourcemap --global-name=ReactPlayer --external:react --footer:js=\"ReactPlayer = ReactPlayer.default;\"",
"build:standalone": "node scripts/build src/standalone.js --outfile=dist/ReactPlayer.standalone.js --format=iife --bundle --minify --sourcemap --global-name=renderReactPlayer --footer:js=\"renderReactPlayer = renderReactPlayer.default;\"",
"build:es6": "node scripts/build src/standalone.js --outfile=dist/ReactPlayer.standalone.es6.js --format=esm --bundle --minify",
"preversion": "npm run lint && npm run test",
"version": "auto-changelog -p && npm run build:dist && npm run build:standalone && git add CHANGELOG.md dist",
"prepublishOnly": "npm run build:lib && npm run build:lazy && npm run build:dist && npm run build:es6 && node scripts/pre-publish.js && cp -r types/* .",
Expand Down Expand Up @@ -79,6 +79,7 @@
"css-loader": "^3.5.2",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"esbuild": "^0.19.4",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^4.2.0",
"mini-css-extract-plugin": "^0.9.0",
Expand Down
38 changes: 38 additions & 0 deletions scripts/build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node
import { parseArgs } from 'node:util';
import { build } from 'esbuild';

const { values: args, positionals } = parseArgs({
options: {},
strict: false,
allowPositionals: true
});

const options = {
target: 'es2019',
logLevel: 'info',
entryPoints: positionals,
outfile: args.outfile,
outdir: args.outfile ? undefined : args.outdir ?? 'dist',
bundle: args.bundle,
minify: args.minify,
format: args.format,
sourcemap: args.sourcemap,
globalName: args['global-name'],
outExtension: args['out-extension'],
plugins: [],
define: {},
loader: {
'.js': 'jsx',
'.html': 'text',
'.css': 'text',
'.svg': 'text',
},
footer: {
js: args['footer:js'] ?? ''
}
};

if (!args.watch) {
await build(options);
}
10 changes: 10 additions & 0 deletions scripts/build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"private": true,
"name": "build",
"version": "0.0.0",
"type": "module",
"main": "./build.js",
"bin": {
"build": "./build.js"
}
}
19 changes: 0 additions & 19 deletions scripts/standalone-es6.js

This file was deleted.

138 changes: 138 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,116 @@
resolved "https://registry.yarnpkg.com/@csstools/sass-import-resolve/-/sass-import-resolve-1.0.0.tgz#32c3cdb2f7af3cd8f0dca357b592e7271f3831b5"
integrity sha512-pH4KCsbtBLLe7eqUrw8brcuFO8IZlN36JjdKlOublibVdAIPHCzEnpBWOVUXK5sCf+DpBi8ZtuWtjF0srybdeA==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.19.4.tgz#74752a09301b8c6b9a415fbda9fb71406a62a7b7"
integrity sha512-mRsi2vJsk4Bx/AFsNBqOH2fqedxn5L/moT58xgg51DjX1la64Z3Npicut2VbhvDFO26qjWtPMsVxCd80YTFVeg==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.19.4.tgz#c27363e1e280e577d9b5c8fa7c7a3be2a8d79bf5"
integrity sha512-uBIbiYMeSsy2U0XQoOGVVcpIktjLMEKa7ryz2RLr7L/vTnANNEsPVAh4xOv7ondGz6ac1zVb0F8Jx20rQikffQ==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.19.4.tgz#6c9ee03d1488973d928618100048b75b147e0426"
integrity sha512-4iPufZ1TMOD3oBlGFqHXBpa3KFT46aLl6Vy7gwed0ZSYgHaZ/mihbYb4t7Z9etjkC9Al3ZYIoOaHrU60gcMy7g==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.19.4.tgz#64e2ee945e5932cd49812caa80e8896e937e2f8b"
integrity sha512-Lviw8EzxsVQKpbS+rSt6/6zjn9ashUZ7Tbuvc2YENgRl0yZTktGlachZ9KMJUsVjZEGFVu336kl5lBgDN6PmpA==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.19.4.tgz#d8e26e1b965df284692e4d1263ba69a49b39ac7a"
integrity sha512-YHbSFlLgDwglFn0lAO3Zsdrife9jcQXQhgRp77YiTDja23FrC2uwnhXMNkAucthsf+Psr7sTwYEryxz6FPAVqw==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.4.tgz#29751a41b242e0a456d89713b228f1da4f45582f"
integrity sha512-vz59ijyrTG22Hshaj620e5yhs2dU1WJy723ofc+KUgxVCM6zxQESmWdMuVmUzxtGqtj5heHyB44PjV/HKsEmuQ==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.19.4.tgz#873edc0f73e83a82432460ea59bf568c1e90b268"
integrity sha512-3sRbQ6W5kAiVQRBWREGJNd1YE7OgzS0AmOGjDmX/qZZecq8NFlQsQH0IfXjjmD0XtUYqr64e0EKNFjMUlPL3Cw==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.19.4.tgz#659f2fa988d448dbf5010b5cc583be757cc1b914"
integrity sha512-ZWmWORaPbsPwmyu7eIEATFlaqm0QGt+joRE9sKcnVUG3oBbr/KYdNE2TnkzdQwX6EDRdg/x8Q4EZQTXoClUqqA==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.19.4.tgz#d5b13a7ec1f1c655ce05c8d319b3950797baee55"
integrity sha512-z/4ArqOo9EImzTi4b6Vq+pthLnepFzJ92BnofU1jgNlcVb+UqynVFdoXMCFreTK7FdhqAzH0vmdwW5373Hm9pg==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.19.4.tgz#878cd8bf24c9847c77acdb5dd1b2ef6e4fa27a82"
integrity sha512-EGc4vYM7i1GRUIMqRZNCTzJh25MHePYsnQfKDexD8uPTCm9mK56NIL04LUfX2aaJ+C9vyEp2fJ7jbqFEYgO9lQ==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.19.4.tgz#df890499f6e566b7de3aa2361be6df2b8d5fa015"
integrity sha512-WVhIKO26kmm8lPmNrUikxSpXcgd6HDog0cx12BUfA2PkmURHSgx9G6vA19lrlQOMw+UjMZ+l3PpbtzffCxFDRg==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.19.4.tgz#76eae4e88d2ce9f4f1b457e93892e802851b6807"
integrity sha512-keYY+Hlj5w86hNp5JJPuZNbvW4jql7c1eXdBUHIJGTeN/+0QFutU3GrS+c27L+NTmzi73yhtojHk+lr2+502Mw==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.19.4.tgz#c49032f4abbcfa3f747b543a106931fe3dce41ff"
integrity sha512-tQ92n0WMXyEsCH4m32S21fND8VxNiVazUbU4IUGVXQpWiaAxOBvtOtbEt3cXIV3GEBydYsY8pyeRMJx9kn3rvw==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.19.4.tgz#0f815a090772138503ee0465a747e16865bf94b1"
integrity sha512-tRRBey6fG9tqGH6V75xH3lFPpj9E8BH+N+zjSUCnFOX93kEzqS0WdyJHkta/mmJHn7MBaa++9P4ARiU4ykjhig==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.19.4.tgz#8d2cca20cd4e7c311fde8701d9f1042664f8b92b"
integrity sha512-152aLpQqKZYhThiJ+uAM4PcuLCAOxDsCekIbnGzPKVBRUDlgaaAfaUl5NYkB1hgY6WN4sPkejxKlANgVcGl9Qg==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.19.4.tgz#f618bec2655de49bff91c588777e37b5e3169d4a"
integrity sha512-Mi4aNA3rz1BNFtB7aGadMD0MavmzuuXNTaYL6/uiYIs08U7YMPETpgNn5oue3ICr+inKwItOwSsJDYkrE9ekVg==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.19.4.tgz#7889744ca4d60f1538d62382b95e90a49687cef2"
integrity sha512-9+Wxx1i5N/CYo505CTT7T+ix4lVzEdz0uCoYGxM5JDVlP2YdDC1Bdz+Khv6IbqmisT0Si928eAxbmGkcbiuM/A==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.19.4.tgz#c3e436eb9271a423d2e8436fcb120e3fd90e2b01"
integrity sha512-MFsHleM5/rWRW9EivFssop+OulYVUoVcqkyOkjiynKBCGBj9Lihl7kh9IzrreDyXa4sNkquei5/DTP4uCk25xw==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.19.4.tgz#f63f5841ba8c8c1a1c840d073afc99b53e8ce740"
integrity sha512-6Xq8SpK46yLvrGxjp6HftkDwPP49puU4OF0hEL4dTxqCbfx09LyrbUj/D7tmIRMj5D5FCUPksBbxyQhp8tmHzw==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.19.4.tgz#80be69cec92da4da7781cf7a8351b95cc5a236b0"
integrity sha512-PkIl7Jq4mP6ke7QKwyg4fD4Xvn8PXisagV/+HntWoDEdmerB2LTukRZg728Yd1Fj+LuEX75t/hKXE2Ppk8Hh1w==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.19.4.tgz#15dc0ed83d2794872b05d8edc4a358fecf97eb54"
integrity sha512-ga676Hnvw7/ycdKB53qPusvsKdwrWzEyJ+AtItHGoARszIqvjffTwaaW3b2L6l90i7MO9i+dlAW415INuRhSGg==

"@esbuild/[email protected]":
version "0.19.4"
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.19.4.tgz#d46a6e220a717f31f39ae80f49477cc3220be0f0"
integrity sha512-HP0GDNla1T3ZL8Ko/SHAS2GgtjOg+VmWnnYLhuTksr++EnduYB0f3Y2LzHsUwb2iQ13JGoY6G3R8h6Du/WG6uA==

"@eslint/eslintrc@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.3.0.tgz#d736d6963d7003b6514e6324bec9c602ac340318"
Expand Down Expand Up @@ -3710,6 +3820,34 @@ es6-error@^4.0.1:
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d"
integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==

esbuild@^0.19.4:
version "0.19.4"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.19.4.tgz#cdf5c4c684956d550bc3c6d0c01dac7fef6c75b1"
integrity sha512-x7jL0tbRRpv4QUyuDMjONtWFciygUxWaUM1kMX2zWxI0X2YWOt7MSA0g4UdeSiHM8fcYVzpQhKYOycZwxTdZkA==
optionalDependencies:
"@esbuild/android-arm" "0.19.4"
"@esbuild/android-arm64" "0.19.4"
"@esbuild/android-x64" "0.19.4"
"@esbuild/darwin-arm64" "0.19.4"
"@esbuild/darwin-x64" "0.19.4"
"@esbuild/freebsd-arm64" "0.19.4"
"@esbuild/freebsd-x64" "0.19.4"
"@esbuild/linux-arm" "0.19.4"
"@esbuild/linux-arm64" "0.19.4"
"@esbuild/linux-ia32" "0.19.4"
"@esbuild/linux-loong64" "0.19.4"
"@esbuild/linux-mips64el" "0.19.4"
"@esbuild/linux-ppc64" "0.19.4"
"@esbuild/linux-riscv64" "0.19.4"
"@esbuild/linux-s390x" "0.19.4"
"@esbuild/linux-x64" "0.19.4"
"@esbuild/netbsd-x64" "0.19.4"
"@esbuild/openbsd-x64" "0.19.4"
"@esbuild/sunos-x64" "0.19.4"
"@esbuild/win32-arm64" "0.19.4"
"@esbuild/win32-ia32" "0.19.4"
"@esbuild/win32-x64" "0.19.4"

escalade@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40"
Expand Down

0 comments on commit 094d6c6

Please sign in to comment.