refactor: cleanup scripts
This commit is contained in:
parent
73eadfe79a
commit
1a34fab1e4
3 changed files with 2 additions and 63 deletions
|
@ -1,5 +1,4 @@
|
|||
import esbuild from 'esbuild';
|
||||
import svelte from '../utils/svelte-plugin.js';
|
||||
import del from 'del';
|
||||
import { promises as fs } from 'fs';
|
||||
import { dim, green, red, yellow } from 'kleur/colors';
|
||||
|
@ -40,7 +39,7 @@ export default async function build(...args) {
|
|||
entryPoints,
|
||||
outdir,
|
||||
format,
|
||||
plugins: [svelte({ isDev })],
|
||||
plugins: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"arg": "^5.0.0",
|
||||
"kleur": "^4.1.4",
|
||||
"esbuild": "0.13.7",
|
||||
"globby": "^12.0.2",
|
||||
"tar": "^6.1.0"
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
// @ts-nocheck
|
||||
import { compile } from 'svelte/compiler';
|
||||
import { relative, isAbsolute, join, dirname } from 'path';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
const convertMessage = ({ message, start, end, filename, frame }) => ({
|
||||
text: message,
|
||||
location: start &&
|
||||
end && {
|
||||
file: filename,
|
||||
line: start.line,
|
||||
column: start.column,
|
||||
length: start.line === end.line ? end.column - start.column : 0,
|
||||
lineText: frame,
|
||||
},
|
||||
});
|
||||
|
||||
const handleLoad = async (args, generate, { isDev }) => {
|
||||
const { path } = args;
|
||||
const source = await fs.readFile(path, 'utf8');
|
||||
const filename = relative(process.cwd(), path);
|
||||
|
||||
try {
|
||||
let compileOptions = { dev: isDev, css: false, generate, hydratable: true };
|
||||
|
||||
let { js, warnings } = compile(source, { ...compileOptions, filename });
|
||||
let contents = js.code + `\n//# sourceMappingURL=` + js.map.toUrl();
|
||||
|
||||
return { loader: 'js', contents, resolveDir: dirname(path), warnings: warnings.map((w) => convertMessage(w)) };
|
||||
} catch (e) {
|
||||
return { errors: [convertMessage(e)] };
|
||||
}
|
||||
};
|
||||
|
||||
export default function sveltePlugin({ isDev = false }) {
|
||||
return {
|
||||
name: 'svelte-esbuild',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /\.svelte$/ }, (args) => {
|
||||
let path = args.path.replace(/\.(?:client|server)/, '');
|
||||
path = isAbsolute(path) ? path : join(args.resolveDir, path);
|
||||
|
||||
if (/\.client\.svelte$/.test(args.path)) {
|
||||
return {
|
||||
path,
|
||||
namespace: 'svelte:client',
|
||||
};
|
||||
}
|
||||
|
||||
if (/\.server\.svelte$/.test(args.path)) {
|
||||
return {
|
||||
path,
|
||||
namespace: 'svelte:server',
|
||||
};
|
||||
}
|
||||
});
|
||||
build.onLoad({ filter: /.*/, namespace: 'svelte:client' }, (args) => handleLoad(args, 'dom', { isDev }));
|
||||
build.onLoad({ filter: /.*/, namespace: 'svelte:server' }, (args) => handleLoad(args, 'ssr', { isDev }));
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue