// @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 })); }, }; } 5/merge Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/scripts/utils/svelte-plugin.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2021-05-17Adds CSS completions to VSCode extension (#214)Gravatar Matthew Phillips 14-5/+1135
2021-05-17chore: remove shhhhh from READMEGravatar Nate Moore 1-2/+1
2021-05-17chore: release v0.10.0Gravatar Nate Moore 13-14/+14
2021-05-17chore: fix versionGravatar Nate Moore 2-7/+3
2021-05-17chore: version packagesGravatar Nate Moore 12-12/+18
2021-05-17chore: bump create-astro depsGravatar Nate Moore 5-4/+10
2021-05-17[ci] yarn formatGravatar natemoo-re 2-1/+3
2021-05-17Version Packages (#213)Gravatar github-actions[bot] 20-34/+51
2021-05-17[ci] yarn formatGravatar natemoo-re 20-99/+102
2021-05-17Fix markdown issues (#208)Gravatar Nate Moore 69-283/+4728
2021-05-16fix: brand colorGravatar Nate Moore 1-1/+1
2021-05-16chore: add file-icon, beautify svgsGravatar Nate Moore 3-2/+47
2021-05-14Fix Windows tests (#212)Gravatar Drew Powers 19-299/+306
2021-05-13[ci] yarn formatGravatar natemoo-re 5-13/+21
2021-05-13fix: formatGravatar Nate Moore 2-3/+3
2021-05-13chore: ignore broken prettier filesGravatar Nate Moore 1-1/+5
2021-05-13chore: format workflow, format `.astro` files (#211)Gravatar Nate Moore 2-1/+2
2021-05-13chore: release astro-vscodeGravatar Nate Moore 6-148/+30
2021-05-13Version Packages (#195)Gravatar github-actions[bot] 23-65/+43
2021-05-13Support for import suggestions in the languageserver (#204)Gravatar Matthew Phillips 6-12/+32
2021-05-13Fix Svelte build output (#201)Gravatar Nate Moore 4-8/+14
2021-05-12[wip] Fix CI (#202)Gravatar Drew Powers 28-219/+191
2021-05-11VS Code extension (#197)Gravatar Matthew Phillips 7-20/+182
2021-05-11Fix workflows! (#198)Gravatar Nate Moore 3-2/+4
2021-05-11Add Astro.request.canonicalURL and Astro.site to global (#199)Gravatar Drew Powers 25-98/+234
2021-05-11Fix portfolio example (#196)Gravatar Drew Powers 2-3/+5
2021-05-10fix: build stuck on unhandled promise reject (#191)Gravatar Kevin (Kun) "Kassimo" Qian 2-2/+13
2021-05-10Allow default import component to be renamed based on import statement defaul...Gravatar Kevin (Kun) "Kassimo" Qian 3-8/+30
2021-05-08Add more docs on styling (#186)Gravatar Drew Powers 1-3/+321
2021-05-08Fix running the extension (#181)Gravatar Matthew Phillips 5-11/+37