This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build
executable file
·69 lines (42 loc) · 2.6 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
set -e
echo ' ╭─ Building NodeKit distribution.'
echo ' ├─── Deleting existing dist/ folder. '
rm -rf dist
echo ' ├─── Creating dist/ folder. '
mkdir -p dist/node_modules
# Create dist/nodekit-bundle.js
#
# PS. The reason we need the banners injected into the esbuild builds:
# https://github.com/evanw/esbuild/issues/946
echo ' ├─── Building nodekit (main process).'
node_modules/esbuild/bin/esbuild bin/nodekit.js --sourcemap=inline --bundle --platform=node --format=esm --outfile=dist/nodekit-bundle.js --external:esbuild --banner:js='import { createRequire as topLevelCreateRequire } from "module"; const require = topLevelCreateRequire(import.meta.url);'
# Create dist/loader-bundle.js
echo ' ├─── Building nodekit (ES Module loader process).'
node_modules/esbuild/bin/esbuild loader.js --sourcemap=inline --bundle --platform=node --format=esm --outfile=dist/loader-bundle.js --external:esbuild --banner:js='import { createRequire as topLevelCreateRequire } from "module"; import { dirname } from "path"; const __filename = fileURLToPath(import.meta.url);const require = topLevelCreateRequire(import.meta.url);'
# Copy esbuild package, including the Linux 64 binary as an external module.
# (esbuild cannot be bundled using esbuild as it contains a binary.)
echo ' ├─── Copying esbuild modules (external).'
cp -R node_modules/esbuild dist/node_modules
cp -R node_modules/esbuild-linux-64 dist/node_modules
echo ' ├─── Copying svelte.'
cp -R node_modules/svelte dist/node_modules
echo ' ├─── Copying app page template (runtime).'
cp -R page-template dist/page-template
# Remove the redundant esbuild binary in the main esbuild package (if it exists)
# as it will copy the binary over from the esbuild-linux-64 package into itself.
# This saves us from including the esbuild binary twice in the distribution package.
rm -f dist/node_modules/esbuild/bin/esbuild
# This script suppresses warnings about experimental ES Module feature usage.
echo ' ├─── Copying experimental warnings suppression script (external).'
cp suppress-experimental.cjs dist/
echo ' ├─── Copying package file (to set ESM mode).'
cp build-templates/package.json dist/
# The launcher script loads the CLI bundle using the ES Module loader bundle,
# specifying the required experimental flats and loading the module to
# suppress experimental module warnings.
echo ' ├─── Copying launcher script (nodekit command).'
cp build-templates/nodekit dist/
echo ' ├─── Making launcher script executable.'
chmod +x dist/nodekit
echo ' ╰─ Done!'