Skip to content

Commit 7feaaa9

Browse files
committed
WIP build
1 parent 899d9b0 commit 7feaaa9

File tree

6 files changed

+139
-7
lines changed

6 files changed

+139
-7
lines changed

esbuild.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import esbuild from 'esbuild';
2+
import fse from 'fs-extra';
3+
import { execSync } from 'child_process';
4+
import { resolve } from 'path';
5+
import { performance } from 'perf_hooks';
6+
7+
const { emptyDir, copy, readJson, writeJson } = fse;
8+
9+
const startTime = performance.now();
10+
const pkg = await readJson('./package.json');
11+
const tsConfig = await readJson('./tsconfig.json');
12+
13+
console.log(`⚡ Building howler.js v${pkg.version}...`);
14+
15+
const outDir = './dist';
16+
const distDir = resolve(outDir);
17+
18+
await emptyDir(distDir);
19+
20+
esbuild
21+
.build({
22+
entryPoints: ['src/core.ts'],
23+
outdir: outDir,
24+
bundle: true,
25+
sourcemap: false,
26+
minify: false,
27+
splitting: false,
28+
format: 'esm',
29+
target: [tsConfig.compilerOptions.target],
30+
platform: 'browser',
31+
external: [],
32+
})
33+
.then(async () => {
34+
// Build declaration files with TSC since they aren't built by esbuild.
35+
execSync('npx tsc');
36+
37+
const declarationsDir = resolve(distDir, 'src');
38+
39+
// Move all declaration files to the root dist folder. Also remove unwanted files and folder.
40+
// await remove(resolve(declarationsDir, 'cli.d.ts'));
41+
await copy(declarationsDir, distDir);
42+
// await remove(declarationsDir);
43+
44+
await writeJson(resolve(distDir, 'package.json'), distPackage, {
45+
spaces: 2,
46+
});
47+
48+
const buildTime = ((performance.now() - startTime) / 1000).toLocaleString(
49+
'en-US',
50+
{
51+
minimumFractionDigits: 3,
52+
maximumFractionDigits: 3,
53+
},
54+
);
55+
console.log(`✅ Finished in ${buildTime} s\n`);
56+
})
57+
.catch((e) => {
58+
console.error(e);
59+
process.exit(1);
60+
});

package-lock.json

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"scripts": {
2525
"test": "vite",
2626
"test:network": "vite --host",
27-
"build": "VERSION=`printf 'v' && node -e 'console.log(require(\"./package.json\").version)'` && sed -i '' '2s/.*/ * howler.js '\"$VERSION\"'/' src/howler.core.js && sed -i '' '4s/.*/ * howler.js '\"$VERSION\"'/' src/plugins/howler.spatial.js && uglifyjs --preamble \"/*! howler.js $VERSION | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */\" src/howler.core.js -c -m --screw-ie8 -o dist/howler.core.min.js && uglifyjs --preamble \"/*! howler.js $VERSION | Spatial Plugin | (c) 2013-2020, James Simpson of GoldFire Studios | MIT License | howlerjs.com */\" src/plugins/howler.spatial.js -c -m --screw-ie8 -o dist/howler.spatial.min.js && awk 'FNR==1{echo \"\"}1' dist/howler.core.min.js dist/howler.spatial.min.js | sed '3s~.*~/*! Spatial Plugin */~' | perl -pe 'chomp if eof' > dist/howler.min.js && awk '(NR>1 && FNR==1){printf (\"\\n\\n\")};1' src/howler.core.js src/plugins/howler.spatial.js > dist/howler.js",
27+
"build": "node esbuild.js",
2828
"release": "VERSION=`printf 'v' && node -e 'console.log(require(\"./package.json\").version)'` && git tag $VERSION && git push && git push origin $VERSION && npm publish"
2929
},
3030
"devDependencies": {
@@ -33,14 +33,17 @@
3333
"typescript": "^4.4.3",
3434
"vite": "^2.5.10"
3535
},
36+
"type": "module",
3637
"main": "dist/howler.js",
3738
"license": "MIT",
3839
"files": [
39-
"src",
4040
"dist/howler.js",
4141
"dist/howler.min.js",
4242
"dist/howler.core.min.js",
4343
"dist/howler.spatial.min.js",
4444
"LICENSE.md"
45-
]
45+
],
46+
"dependencies": {
47+
"fs-extra": "^10.0.0"
48+
}
4649
}

src/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* MIT License
99
*/
10-
import Howler from './Howler';
11-
import Howl from './Howl';
10+
import Howler from './howler';
11+
import Howl from './howl';
1212

1313
export { Howler, Howl };

src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Howl, { HowlXHROptions } from './Howl';
1+
import Howl, { HowlXHROptions } from './howl';
22
import Howler, { HowlerAudioContext } from './howler';
33

44
export const cache = {};

src/howler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Howl from './Howl';
1+
import Howl from './howl';
22

33
export interface HowlerAudioElement extends HTMLAudioElement {
44
_unlocked: boolean;

0 commit comments

Comments
 (0)