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

meta: replace browserify with esbuild #3363

Merged
merged 8 commits into from
Jan 13, 2022
Merged
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
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = (api) => {
useBuiltIns: false, // Don't add polyfills automatically.
// We can uncomment the following line if we start adding polyfills to the non-legacy dist files.
// corejs: { version: '3.15', proposals: true },
modules: false,
}],
],
plugins: [
Expand Down
136 changes: 0 additions & 136 deletions bin/build-bundle.js

This file was deleted.

101 changes: 101 additions & 0 deletions bin/build-bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env node

import fs from 'node:fs/promises'
import path from 'node:path'
import chalk from 'chalk'

import esbuild from 'esbuild'
import babel from 'esbuild-plugin-babel'

const UPPY_ROOT = new URL('../', import.meta.url)
const PACKAGES_ROOT = new URL('./packages/', UPPY_ROOT)

function buildBundle (srcFile, bundleFile, { minify = true, standalone = '', plugins, target } = {}) {
return esbuild.build({
bundle: true,
sourcemap: true,
entryPoints: [srcFile],
outfile: bundleFile,
banner: {
js: '"use strict";',
},
minify,
plugins,
target,
}).then(() => {
if (minify) {
console.info(chalk.green(`✓ Built Minified Bundle [${standalone}]:`), chalk.magenta(bundleFile))
} else {
console.info(chalk.green(`✓ Built Bundle [${standalone}]:`), chalk.magenta(bundleFile))
}
})
}

await fs.mkdir(new URL('./uppy/dist', PACKAGES_ROOT), { recursive: true })
await fs.mkdir(new URL('./@uppy/robodog/dist', PACKAGES_ROOT), { recursive: true })
await fs.mkdir(new URL('./@uppy/locales/dist', PACKAGES_ROOT), { recursive: true })

const methods = [
buildBundle(
'./packages/uppy/index.js',
'./packages/uppy/dist/uppy.min.js',
{ standalone: 'Uppy' },
),
buildBundle(
'./packages/uppy/bundle.js',
'./packages/uppy/dist/uppy.legacy.min.js',
{
standalone: 'Uppy (with polyfills)',
target: 'es5',
plugins:[babel({
config:{
compact: false,
highlightCode: false,
inputSourceMap: true,

browserslistEnv: 'legacy',
presets: [['@babel/preset-env', {
loose: false,
targets: { ie:11 },
useBuiltIns: 'entry',
corejs: { version: '3.15', proposals: true },
}]],
},
})],
},
),
buildBundle(
'./packages/@uppy/robodog/bundle.js',
'./packages/@uppy/robodog/dist/robodog.min.js',
{ standalone: 'Robodog' },
),
]

// Build minified versions of all the locales
const localesModules = await fs.opendir(new URL('./@uppy/locales/src/', PACKAGES_ROOT))
for await (const dirent of localesModules) {
if (!dirent.isDirectory() && dirent.name.endsWith('.js')) {
const localeName = path.basename(dirent.name, '.js')
methods.push(
buildBundle(
`./packages/@uppy/locales/src/${localeName}.js`,
`./packages/@uppy/locales/dist/${localeName}.min.js`,
{ minify: true },
),
)
}
}

// Add BUNDLE-README.MD
methods.push(
fs.copyFile(
new URL('./BUNDLE-README.md', UPPY_ROOT),
new URL('./uppy/dist/README.md', PACKAGES_ROOT),
),
)

Promise.all(methods).then(() => {
console.info(chalk.yellow('✓ JS bundles 🎉'))
}, (err) => {
console.error(chalk.red('✗ Error:'), chalk.red(err.message))
})
5 changes: 2 additions & 3 deletions bin/build-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const glob = promisify(require('glob'))
const fs = require('fs')
const path = require('path')

const transformFile = promisify(babel.transformFile)
const { mkdir, stat, writeFile } = fs.promises

const SOURCE = 'packages/{*,@uppy/*}/src/**/*.js'
Expand Down Expand Up @@ -52,7 +51,7 @@ async function buildLib () {
}
}

const { code, map } = await transformFile(file, { sourceMaps: true })
const { code, map } = await babel.transformFileAsync(file, { sourceMaps: true })
await mkdir(path.dirname(libFile), { recursive: true })
await Promise.all([
writeFile(libFile, code),
Expand All @@ -66,6 +65,6 @@ async function buildLib () {
console.log('Using Babel version:', require('@babel/core/package.json').version)

buildLib().catch((err) => {
console.error(err.stack)
console.error(err)
process.exit(1)
})
44 changes: 0 additions & 44 deletions bin/disc.js

This file was deleted.

31 changes: 13 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@
"@typescript-eslint/parser": "^5.0.0",
"@uppy-dev/remark-lint-uppy": "workspace:*",
"adm-zip": "^0.5.5",
"aliasify": "^2.1.0",
"autoprefixer": "^10.2.6",
"aws-sdk": "^2.1038.0",
"babel-jest": "^27.0.6",
"babel-plugin-inline-package-json": "^2.0.0",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"chalk": "^4.1.1",
"concat-stream": "^2.0.0",
"core-js": "~3.19.3",
"cssnano": "^5.0.6",
"dedent": "^0.7.0",
"deep-freeze": "^0.0.1",
"disc": "^1.3.3",
"esbuild": "^0.14.1",
"esbuild-plugin-babel": "^0.2.3",
"eslint": "^8.0.0",
"eslint-config-transloadit": "^2.0.0",
"eslint-plugin-compat": "^4.0.0",
Expand Down Expand Up @@ -114,16 +112,12 @@
"stylelint-scss": "^3.20.1",
"tar": "^6.1.0",
"temp-write": "^5.0.0",
"terser": "^5.7.0",
"tinyify": "^3.0.0",
"tsd": "^0.17.0",
"tsify": "^5.0.1",
"typescript": "~4.4",
"verdaccio": "^5.1.1",
"watchify": "^4.0.0"
"verdaccio": "^5.1.1"
},
"scripts": {
"build:bundle": "yarn node ./bin/build-bundle.js",
"build:bundle": "yarn node ./bin/build-bundle.mjs",
"build:clean": "rm -rf packages/*/lib packages/@uppy/*/lib packages/*/dist packages/@uppy/*/dist",
"build:companion": "yarn workspace @uppy/companion build",
"build:css": "yarn node ./bin/build-css.js",
Expand Down Expand Up @@ -159,22 +153,23 @@
"test": "npm-run-all lint test:locale-packs test:unit test:type test:companion",
"uploadcdn": "yarn node ./bin/upload-to-cdn.js",
"version": "yarn node ./bin/after-version-bump.js",
"watch:css": "onchange 'packages/**/*.scss' --initial --verbose -- yarn run build:css",
"watch:css": "onchange 'packages/{@uppy/,}*/src/*.scss' --initial --verbose -- yarn run build:css",
"watch:js:bundle": "onchange 'packages/{@uppy/,}*/src/**/*.js' --initial --verbose -- yarn run build:bundle",
"watch:js:lib": "onchange 'packages/{@uppy/,}*/src/**/*.js' --initial --verbose -- yarn run build:lib",
"watch": "npm-run-all --parallel watch:**",
"watch:js": "npm-run-all --parallel watch:js:bundle watch:js:lib",
"watch": "npm-run-all --parallel watch:css watch:js",
"web:build-examples": "cd website && node build-examples.js",
"web:build": "npm-run-all web:inject-disc web:inject-bundles-misc web:generate web:build-examples web:inject-frontpagecodesample",
"web:build": "npm-run-all web:inject-bundles-misc web:generate web:build-examples web:inject-frontpagecodesample",
"web:bundle-watch-inject": "onchange 'packages/uppy/dist/**/*.css' 'packages/uppy/dist/**/*.js' --initial --verbose -- yarn run web:inject-bundles-misc",
"web:clean": "cd website && touch db.json && yarn run hexo clean",
"web:prepare-deploy": "bash ./bin/prepare-web-deploy",
"web:generate": "cd website && touch db.json && yarn run hexo generate",
"web:inject-bundles-misc": "cd website && node inject.js",
"web:inject-disc": "yarn run build:lib && node ./bin/disc.js",
"web:inject-frontpagecodesample": "yarn run web:generate && cp -f website/public/frontpage-code-sample.html website/themes/uppy/layout/partials/frontpage-code-sample.html && touch website/themes/uppy/layout/index.ejs",
"web:start": "npm-run-all build:lib --parallel watch:css web:watch-examples web:bundle-watch-inject web:watch",
"web:watch-examples": "cd website && node build-examples.js watch",
"web:watch": "cd website && touch db.json && yarn run hexo server"
"web:start-server": "cd website && touch db.json && node inject.js && node build-examples.js && yarn run hexo server",
"web:start": "yarn run web:start-server",
"web:watch-examples": "yarn run web:bundle-watch-inject && yarn run web:watch",
"web:watch": "npm-run-all build:lib --parallel watch:css web:watch-examples web:bundle-watch-inject web:start_server"
},
"jest": {
"automock": false,
Expand All @@ -190,6 +185,6 @@
"@types/redis": "2",
"@types/eslint@^7.2.13": "^8.2.0",
"npm-auth-to-token@1.0.0": "patch:npm-auth-to-token@npm:1.0.0#.yarn/patches/npm-auth-to-token-npm-1.0.0-c288ce201f",
"babel-plugin-transform-commonjs@1.1.6": "patch:babel-plugin-transform-commonjs@npm:1.1.6#.yarn/patches/babel-plugin-transform-commonjs-npm-1.1.6-0007fa2809"
"babel-plugin-transform-commonjs@2.1.6": "patch:babel-plugin-transform-commonjs@npm:1.1.6#.yarn/patches/babel-plugin-transform-commonjs-npm-1.1.6-0007fa2809"
}
}
Loading