Skip to content

Commit fb42fae

Browse files
authored
Merge pull request #50 from tilde-lab/esbuild
Esbuild by @Valexr (HIGHLY EXPERIMENTAL)
2 parents cf9eae0 + 41390b2 commit fb42fae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1581
-42870
lines changed

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{js,css,html,json,svelte}]
8+
charset = utf-8
9+
indent_style = tab
10+
indent_size = 4
11+
trim_trailing_whitespace = true
12+
max_line_length = 100

.eslintrc.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/surge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install node
1414
uses: actions/setup-node@v2
1515
with:
16-
node-version: "14"
16+
node-version: "16"
1717

1818
# Install npm packages
1919
- name: Install packages

.gitignore

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/node_modules/
2-
/dist/
3-
/cypress/screenshots/
4-
.DS_Store
5-
.idea/
6-
.sessions/
7-
.vscode/
8-
Thumbs.db
9-
*.log
1+
node_modules
2+
dist/*
3+
*-lock.*

app.config.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

copy.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cpSync } from 'fs';
2+
import { join, dirname } from 'path';
3+
4+
export default function copy({ from, to }) {
5+
return {
6+
name: 'copy',
7+
setup(build) {
8+
build.onEnd(() => cpSync(from, join(dirname(build.initialOptions.outfile), to), {
9+
recursive: true,
10+
force: true,
11+
dereference: true
12+
}));
13+
},
14+
};
15+
}

esbuild.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { build } from 'esbuild';
2+
import { derver } from 'derver';
3+
import svelte from 'esbuild-svelte';
4+
import preprocess from 'svelte-preprocess';
5+
import { eslintPlugin } from 'esbuild-plugin-eslinter';
6+
import copy from './copy.js';
7+
import html from './html.js';
8+
9+
const DEV = process.argv.includes('--dev');
10+
11+
build({
12+
bundle: true,
13+
entryPoints: ['src/main.ts'],
14+
outfile: 'dist/build/bundle.js',
15+
write: DEV,
16+
minify: !DEV,
17+
incremental: DEV,
18+
sourcemap: DEV && 'inline',
19+
loader: { '.svg': 'text' },
20+
legalComments: 'none',
21+
logLevel: 'debug',
22+
mainFields: [
23+
'svelte',
24+
'browser',
25+
'module',
26+
'main'
27+
],
28+
plugins: [
29+
svelte({
30+
compileOptions: {
31+
dev: DEV,
32+
css: false,
33+
immutable: true,
34+
legacy: false
35+
},
36+
preprocess: [
37+
preprocess({
38+
sourceMap: DEV,
39+
typescript: true,
40+
scss: {
41+
quietDeps: true,
42+
renderSync: true,
43+
}
44+
})
45+
]
46+
47+
}),
48+
eslintPlugin(),
49+
copy({ from: './src/assets', to: '../assets' }),
50+
html({ in: 'src/index.html', out: 'dist/index.html', dev: DEV }),
51+
]
52+
53+
}).then(bundle => {
54+
DEV && derver({
55+
dir: 'dist',
56+
host: 'localhost',
57+
port: 5555,
58+
watch: ['dist', 'src'],
59+
onwatch: async (lr, item) => {
60+
if (item == 'src') {
61+
lr.prevent();
62+
bundle.rebuild().catch(err => lr.error(err.message, 'Svelte compile error'));
63+
}
64+
}
65+
});
66+
}).catch(e => console.log(e.errors));
67+

html.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { readFile, writeFile } from "fs/promises";
2+
3+
export default function html(options = {}) {
4+
return {
5+
name: 'html',
6+
setup(build) {
7+
build.onEnd(async (result) => {
8+
let html = await readFile(options.in);
9+
10+
html = html.toString();
11+
12+
if (options.dev) {
13+
const linkedReplace = `\t<link rel='stylesheet' href='build/bundle.css'>\n\t<script defer src='build/bundle.js'></script>\n</head>`;
14+
html = html.replace('</head>', linkedReplace);
15+
} else {
16+
let [js, css] = result.outputFiles;
17+
18+
html = html
19+
.replace('</head>', () => `<style>\n${css.text}</style>\n</head>`)
20+
.replace('</body>', () => `<script>\n${js.text}</script>\n</body>`);
21+
}
22+
23+
await writeFile(options.out, html, { encoding: 'utf8' });
24+
});
25+
},
26+
};
27+
}

index.html

Lines changed: 0 additions & 15950 deletions
This file was deleted.

0 commit comments

Comments
 (0)