Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit c200434

Browse files
committed
Fix css loader
1 parent fe4272a commit c200434

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

plugins/css.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,26 @@ export const cssLoader = async ({ specifier, data }: LoadInput, aleph: Aleph): P
105105
} catch (err) {
106106
log.warn('postcss:', err.message || err)
107107
}
108+
} else {
109+
css = sourceCode
108110
}
109111

110-
try {
111-
const ret = await esbuild({
112-
stdin: {
113-
loader: 'css',
114-
sourcefile: specifier,
115-
contents: css
116-
},
117-
write: false,
118-
bundle: true,
119-
minify: aleph.mode === 'production',
120-
plugins: [esmLoader],
121-
})
122-
css = util.trimSuffix(ret.outputFiles[0].text, '\n')
123-
} catch (e) { }
112+
if (!Deno.env.get('DENO_TESTING')) {
113+
try {
114+
const ret = await esbuild({
115+
stdin: {
116+
loader: 'css',
117+
sourcefile: specifier,
118+
contents: css
119+
},
120+
write: false,
121+
bundle: true,
122+
minify: aleph.mode === 'production',
123+
plugins: [esmLoader],
124+
})
125+
css = util.trimSuffix(ret.outputFiles[0].text, '\n')
126+
} catch (e) { }
127+
}
124128

125129
ms.stop(`process ${specifier}`)
126130

plugins/css_test.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { delay } from 'std/async/delay.ts'
21
import { exists } from 'std/fs/exists.ts'
32
import { join } from 'std/path/mod.ts'
43
import { assert, assertEquals } from 'std/testing/asserts.ts'
5-
import { stopEsbuild } from '../bundler/esbuild.ts'
64
import { Aleph } from '../server/aleph.ts'
75
import { computeHash } from '../server/helper.ts'
86
import { ensureTextFile } from '../shared/fs.ts'
@@ -30,30 +28,6 @@ Deno.test('plugin: css loader', async () => {
3028
assert(!isCSS('/style/index.sass'))
3129
})
3230

33-
Deno.test({
34-
name: 'plugin: css loader in production mode',
35-
fn: async () => {
36-
Deno.env.set('DENO_TESTING', 'true')
37-
const dir = await Deno.makeTempDir({ prefix: 'aleph_plugin_testing' })
38-
const aleph = new Aleph(dir, 'production')
39-
await ensureTextFile(
40-
join(dir, '/style/index.css'),
41-
'h1 { font-size: 18px; }'
42-
)
43-
const { code } = await cssLoader({ specifier: '/style/index.css', }, aleph)
44-
assertEquals(code, [
45-
'import { applyCSS } from "https://deno.land/x/aleph/framework/core/style.ts"',
46-
'export const css = "h1{font-size:18px}"',
47-
'export default {}',
48-
'applyCSS("/style/index.css", { css })',
49-
].join('\n'))
50-
51-
stopEsbuild()
52-
await delay(150) // wait esbuild stop
53-
},
54-
sanitizeResources: false,
55-
})
56-
5731
Deno.test('plugin: css loader with extract size option', async () => {
5832
Deno.env.set('DENO_TESTING', 'true')
5933
const dir = await Deno.makeTempDir({ prefix: 'aleph_plugin_testing' })
@@ -78,6 +52,7 @@ Deno.test('plugin: css loader for remote external', async () => {
7852
Deno.env.set('DENO_TESTING', 'true')
7953
const dir = await Deno.makeTempDir({ prefix: 'aleph_plugin_testing' })
8054
const aleph = new Aleph(dir, 'development')
55+
aleph.config.css.cache = false
8156
const { code } = await cssLoader({ specifier: 'https://esm.sh/tailwindcss/dist/tailwind.min.css', }, aleph)
8257
assertEquals(code, [
8358
'import { applyCSS } from "https://deno.land/x/aleph/framework/core/style.ts"',

0 commit comments

Comments
 (0)