-
-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change exports to fix bundles (#1812)
* change exports to fix bundles * use browserify for bundling * revert exports * use browserify in bundle script
- Loading branch information
1 parent
8fccddb
commit f68ef8f
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict" | ||
|
||
const fs = require("fs") | ||
const path = require("path") | ||
const browserify = require("browserify") | ||
const {minify} = require("terser") | ||
|
||
const [sourceFile, outFile, globalName] = process.argv.slice(2) | ||
|
||
const json = require(path.join(__dirname, "..", "package.json")) | ||
const bundleDir = path.join(__dirname, "..", "bundle") | ||
if (!fs.existsSync(bundleDir)) fs.mkdirSync(bundleDir) | ||
|
||
browserify({standalone: globalName}) | ||
.require(path.join(__dirname, "../dist", sourceFile), {expose: sourceFile}) | ||
.bundle(saveAndMinify) | ||
|
||
async function saveAndMinify(err, buf) { | ||
if (err) { | ||
console.error("browserify error:", err) | ||
process.exit(1) | ||
} | ||
|
||
const bundlePath = path.join(bundleDir, outFile) | ||
const opts = { | ||
ecma: 2018, | ||
warnings: true, | ||
compress: { | ||
pure_getters: true, | ||
keep_infinity: true, | ||
unsafe_methods: true, | ||
}, | ||
format: { | ||
preamble: `/* ${json.name} ${json.version} (${globalName}): ${json.description} */`, | ||
}, | ||
sourceMap: { | ||
filename: outFile + ".min.js", | ||
url: outFile + ".min.js.map", | ||
}, | ||
} | ||
|
||
const result = await minify(buf.toString(), opts) | ||
|
||
fs.writeFileSync(bundlePath + ".bundle.js", buf) | ||
fs.writeFileSync(bundlePath + ".min.js", result.code) | ||
fs.writeFileSync(bundlePath + ".min.js.map", result.map) | ||
if (result.warnings) result.warnings.forEach((msg) => console.warn("terser.minify warning:", msg)) | ||
} |