|
| 1 | +// @deno-types="https://deno.land/x/[email protected]/mod.d.ts" |
| 2 | +import { build, stop, Plugin } from 'https://deno.land/x/[email protected]/mod.js' |
1 | 3 | import { join } from 'https://deno.land/[email protected]/path/mod.ts'
|
2 | 4 | import { cache } from '../server/cache.ts'
|
3 | 5 | import util from '../shared/util.ts'
|
4 |
| -// @deno-types="https://deno.land/x/[email protected]/mod.d.ts" |
5 |
| -import { build, stop, Plugin } from 'https://deno.land/x/[email protected]/mod.js' |
6 | 6 |
|
7 | 7 | export {
|
8 | 8 | build as esbuild,
|
9 | 9 | stop as stopEsbuild
|
10 | 10 | }
|
11 | 11 |
|
12 |
| -export const esmLoader: Plugin = { |
13 |
| - name: 'esm-loader', |
| 12 | +export const cssPlugin: Plugin = { |
| 13 | + name: 'css-resolver', |
| 14 | + setup(build) { |
| 15 | + build.onResolve({ filter: /.*/ }, args => { |
| 16 | + const isRemote = util.isLikelyHttpURL(args.path) |
| 17 | + const path = isRemote ? args.path : util.trimPrefix(args.path, 'file://') |
| 18 | + |
| 19 | + if ( |
| 20 | + args.kind === 'url-token' || |
| 21 | + (args.kind === 'import-rule' && (isRemote || path.startsWith('/'))) |
| 22 | + ) { |
| 23 | + return { path: path, external: true } |
| 24 | + } |
| 25 | + |
| 26 | + // ensure the `path` is an absolute path |
| 27 | + if (!path.startsWith('/')) { |
| 28 | + return { path: join(args.resolveDir, path) } |
| 29 | + } |
| 30 | + |
| 31 | + return { path } |
| 32 | + }) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +export const denoPlugin: Plugin = { |
| 37 | + name: 'deno-resolve-loader', |
14 | 38 | setup(build) {
|
15 | 39 | build.onResolve({ filter: /.*/ }, args => {
|
16 | 40 | const isRemote = util.isLikelyHttpURL(args.path)
|
17 | 41 | const path = isRemote ? args.path : util.trimPrefix(args.path, 'file://')
|
18 | 42 |
|
| 43 | + |
| 44 | + console.log(args) |
19 | 45 | if (
|
20 | 46 | args.kind === 'url-token' ||
|
21 | 47 | (args.kind === 'import-rule' && (isRemote || path.startsWith('/')))
|
22 | 48 | ) {
|
23 | 49 | return { path: path, external: true }
|
24 | 50 | }
|
| 51 | + |
25 | 52 | if (isRemote) {
|
26 | 53 | return {
|
27 | 54 | path,
|
28 |
| - namespace: 'http-module', |
| 55 | + namespace: 'http', |
29 | 56 | }
|
30 | 57 | }
|
31 |
| - if (args.namespace === 'http-module') { |
| 58 | + |
| 59 | + if (args.namespace === 'http') { |
32 | 60 | return {
|
33 | 61 | path: (new URL(path, args.importer)).toString(),
|
34 |
| - namespace: 'http-module', |
| 62 | + namespace: 'http', |
35 | 63 | }
|
36 | 64 | }
|
37 |
| - if (path.startsWith('.')) { |
| 65 | + |
| 66 | + // ensure the `path` is an absolute path |
| 67 | + if (!path.startsWith('/')) { |
38 | 68 | return { path: join(args.resolveDir, path) }
|
39 | 69 | }
|
| 70 | + |
40 | 71 | return { path }
|
41 | 72 | })
|
42 |
| - build.onLoad({ filter: /.*/, namespace: 'http-module' }, async args => { |
| 73 | + |
| 74 | + build.onLoad({ filter: /.*/, namespace: 'http' }, async args => { |
43 | 75 | const { content } = await cache(args.path)
|
44 | 76 | return { contents: content }
|
45 | 77 | })
|
|
0 commit comments