|
@@ -7,11 +7,14 @@ const browserify = require('browserify')
|
|
|
const exorcist = require('exorcist')
|
|
|
const glob = require('glob')
|
|
|
const path = require('path')
|
|
|
+const { minify } = require('terser')
|
|
|
+const { transformFileAsync } = require('@babel/core')
|
|
|
|
|
|
function handleErr (err) {
|
|
|
console.error(chalk.red('✗ Error:'), chalk.red(err.message))
|
|
|
}
|
|
|
|
|
|
+// eslint-disable-next-line no-shadow
|
|
|
function buildBundle (srcFile, bundleFile, { minify = false, standalone = '' } = {}) {
|
|
|
const b = browserify(srcFile, { debug: true, standalone })
|
|
|
if (minify) {
|
|
@@ -31,10 +34,59 @@ function buildBundle (srcFile, bundleFile, { minify = false, standalone = '' } =
|
|
|
} else {
|
|
|
console.info(chalk.green(`✓ Built Bundle [${standalone}]:`), chalk.magenta(bundleFile))
|
|
|
}
|
|
|
- resolve()
|
|
|
+ resolve([bundleFile, standalone])
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
+async function minifyBundle ([bundleFile, standalone]) {
|
|
|
+ const minifiedFilePath = bundleFile.replace(/\.js$/, '.min.js')
|
|
|
+ const sourceMapPath = `${minifiedFilePath}.map`
|
|
|
+ const js = await fs.promises.readFile(bundleFile, 'utf-8')
|
|
|
+ const { code, map } = await minify(js, {
|
|
|
+ sourceMap: {
|
|
|
+ content: fs.readFileSync(`${bundleFile}.map`, 'utf-8'),
|
|
|
+ url:sourceMapPath,
|
|
|
+ },
|
|
|
+ toplevel: true,
|
|
|
+ })
|
|
|
+ return Promise.all([
|
|
|
+ fs.promises.writeFile(minifiedFilePath, code),
|
|
|
+ fs.promises.writeFile(sourceMapPath, map),
|
|
|
+ ])
|
|
|
+ .then(() => console.info(chalk.green(`✓ Built Minified Bundle [${standalone}]:`), chalk.magenta(minifiedFilePath)))
|
|
|
+}
|
|
|
+async function transpileDownForIE ([bundleFile, standalone]) {
|
|
|
+ const minifiedFilePath = bundleFile.replace(/\.js$/, '.min.js')
|
|
|
+ const sourceMapPath = `${minifiedFilePath}.map`
|
|
|
+ const { code: js, map: inputMap } = await transformFileAsync(bundleFile, {
|
|
|
+ compact: false,
|
|
|
+ highlightCode: false,
|
|
|
+ inputSourceMap: true,
|
|
|
+
|
|
|
+ browserslistEnv: 'legacy',
|
|
|
+ presets: [['@babel/preset-env', {
|
|
|
+ modules: false,
|
|
|
+ loose: true,
|
|
|
+ targets: { ie:11 },
|
|
|
+ }]],
|
|
|
+ })
|
|
|
+ const { code, map } = await minify(js, {
|
|
|
+ sourceMap: {
|
|
|
+ content: inputMap,
|
|
|
+ url: sourceMapPath,
|
|
|
+ },
|
|
|
+ toplevel: true,
|
|
|
+ })
|
|
|
+ return Promise.all([
|
|
|
+ fs.promises.writeFile(bundleFile, js),
|
|
|
+ fs.promises.writeFile(`${bundleFile}.map`, JSON.stringify(inputMap)),
|
|
|
+ fs.promises.writeFile(minifiedFilePath, code),
|
|
|
+ fs.promises.writeFile(sourceMapPath, map),
|
|
|
+ ]).then(() => {
|
|
|
+ console.info(chalk.green(`✓ Built Bundle [${standalone} (ES5)]:`), chalk.magenta(bundleFile))
|
|
|
+ console.info(chalk.green(`✓ Built Minified Bundle [${standalone} (ES5)]:`), chalk.magenta(minifiedFilePath))
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
mkdirp.sync('./packages/uppy/dist')
|
|
|
mkdirp.sync('./packages/@uppy/robodog/dist')
|
|
@@ -42,25 +94,20 @@ mkdirp.sync('./packages/@uppy/locales/dist')
|
|
|
|
|
|
const methods = [
|
|
|
buildBundle(
|
|
|
- './packages/uppy/bundle.js',
|
|
|
+ './packages/uppy/index.js',
|
|
|
'./packages/uppy/dist/uppy.js',
|
|
|
{ standalone: 'Uppy' }
|
|
|
- ),
|
|
|
+ ).then(minifyBundle),
|
|
|
buildBundle(
|
|
|
'./packages/uppy/bundle.js',
|
|
|
- './packages/uppy/dist/uppy.min.js',
|
|
|
- { standalone: 'Uppy', minify: true }
|
|
|
- ),
|
|
|
+ './packages/uppy/dist/uppy.legacy.js',
|
|
|
+ { standalone: 'Uppy (with polyfills)' }
|
|
|
+ ).then(transpileDownForIE),
|
|
|
buildBundle(
|
|
|
'./packages/@uppy/robodog/bundle.js',
|
|
|
'./packages/@uppy/robodog/dist/robodog.js',
|
|
|
{ standalone: 'Robodog' }
|
|
|
- ),
|
|
|
- buildBundle(
|
|
|
- './packages/@uppy/robodog/bundle.js',
|
|
|
- './packages/@uppy/robodog/dist/robodog.min.js',
|
|
|
- { standalone: 'Robodog', minify: true }
|
|
|
- ),
|
|
|
+ ).then(minifyBundle),
|
|
|
]
|
|
|
|
|
|
// Build minified versions of all the locales
|