Skip to content

Commit

Permalink
build: update bundle-module script for node14
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 5, 2020
1 parent c9f3f18 commit 2b60249
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions scripts/bundle-module
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const deps = Object.keys(pkg.dependencies || {}).reduce(
const INPUT_OPTS = {
external: Object.keys(deps),
input: "./index.js",
plugins: [cleanup({ comments: "some" })]
plugins: [cleanup({ comments: "some" })],
};

const TERSER_OPTS = {
compress: true,
mangle: true,
ecma: 6
ecma: 6,
};

const buildVersion = async (opts, write = true, compressed = false) => {
Expand All @@ -42,55 +42,61 @@ const buildVersion = async (opts, write = true, compressed = false) => {
const gzSize = gz.sync(terserOut);

write && fs.writeFileSync(opts.file, compressed ? terserOut : bundleCode);
opts.sourcemap && fs.writeFileSync(opts.file + ".map", bundleOut.map);
opts.sourcemap &&
fs.writeFileSync(opts.file + ".map", bundleOut.map.toString());

console.log(`\tsize: ${size(terserOut.length)} / gzipped: ${size(gzSize)}`);
return { raw: bundleCode.length, min: terserOut.length, gzip: gzSize };
};

const build = async () => {
!fs.existsSync("lib") && fs.mkdirSync("lib");
!fs.existsSync(".meta") && fs.mkdirSync(".meta");

let cjs, esm, umd;

cjs = await buildVersion({
file: "lib/index.js",
format: "cjs",
// we don't use default exports, so safe to remove interop blocks
interop: false,
sourcemap: true,
sourcemapExcludeSources: true
});

if (buidAll) {
// output disabled, just collect meta data
esm = await buildVersion(
{
file: "lib/index.es6.js",
format: "esm",
interop: false
},
false
);

// write minified version
umd = await buildVersion(
{
file: "lib/index.umd.js",
format: "umd",
globals: deps,
name: `thi.ng.${name}`,
interop: false,
sourcemap: true,
sourcemapExcludeSources: true
},
true,
true
);
try {
!fs.existsSync("lib") && fs.mkdirSync("lib");
!fs.existsSync(".meta") && fs.mkdirSync(".meta");

let cjs, esm, umd;

cjs = await buildVersion({
file: "lib/index.js",
format: "cjs",
// we don't use default exports, so safe to remove interop blocks
interop: false,
sourcemap: true,
sourcemapExcludeSources: true,
});

if (buidAll) {
// output disabled, just collect meta data
esm = await buildVersion(
{
file: "lib/index.es6.js",
format: "esm",
interop: false,
},
false
);

// write minified version
umd = await buildVersion(
{
file: "lib/index.umd.js",
format: "umd",
globals: deps,
name: `thi.ng.${name}`,
interop: false,
sourcemap: true,
sourcemapExcludeSources: true,
},
true,
true
);
}

fs.writeFileSync(".meta/size.json", JSON.stringify({ esm, cjs, umd }));
} catch (e) {
console.warn(e);
process.exit(1);
}

fs.writeFileSync(".meta/size.json", JSON.stringify({ esm, cjs, umd }));
};

build();

0 comments on commit 2b60249

Please sign in to comment.