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

Commit 0d2e104

Browse files
committed
Improve css loader
1 parent 7b6e1e7 commit 0d2e104

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

plugins/css.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { extname, join } from 'https://deno.land/[email protected]/path/mod.ts'
1+
import { join } from 'https://deno.land/[email protected]/path/mod.ts'
22
import { esbuild, esmLoader } from '../bundler/esbuild.ts'
3-
import { toLocalPath, computeHash } from '../server/helper.ts'
43
import { existsFile } from '../shared/fs.ts'
54
import log, { Measure } from '../shared/log.ts'
65
import util from '../shared/util.ts'
7-
import type { Aleph, LoadInput, LoadOutput, Plugin, PostCSSPlugin } from '../types.d.ts'
6+
import type { Aleph, LoadInput, LoadOutput, PostCSSPlugin } from '../types.d.ts'
87

9-
const test = /\.(css|pcss|postcss)$/i
108
const postcssVersion = '8.3.6'
11-
const postcssModulesVersion = '4.1.3'
9+
const postcssModulesVersion = '4.2.2'
1210
const productionOnlyPostcssPlugins = ['autoprefixer']
1311
const isModulesPluginName = (v: any): v is string => (typeof v === 'string' && /^postcss\-modules(@|$)/i.test(v.trim()))
1412

@@ -144,8 +142,6 @@ export const cssLoader = async ({ specifier, data }: LoadInput, aleph: Aleph): P
144142
}
145143
}
146144

147-
export const isCSS = (specifier: string): boolean => test.test(specifier)
148-
149145
async function initPostCSS(plugins: PostCSSPlugin[], isDev: boolean) {
150146
const postPlugins = await Promise.all(plugins.filter(p => {
151147
if (isDev) {
@@ -179,16 +175,7 @@ async function initPostCSS(plugins: PostCSSPlugin[], isDev: boolean) {
179175
}
180176

181177
async function importPostcssPluginByName(name: string) {
182-
const url = `https://esm.sh/${name}?deps=postcss@${postcssVersion}&no-check`
178+
const url = `https://esm.sh/${name}?deps=postcss@${postcssVersion}&bundle&no-check`
183179
const { default: Plugin } = await import(url)
184180
return Plugin
185181
}
186-
187-
export default (): Plugin => {
188-
return {
189-
name: 'css-loader',
190-
setup: aleph => {
191-
aleph.onResolve(test, () => ({ acceptHMR: true }))
192-
}
193-
}
194-
}

server/aleph.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { wasmChecksum, parseExportNames, SourceType, transform, stripSsrCode } f
1010
import { EventEmitter } from '../framework/core/events.ts'
1111
import { builtinModuleExts, toPagePath, trimBuiltinModuleExts } from '../framework/core/module.ts'
1212
import { Routing } from '../framework/core/routing.ts'
13-
import cssPlugin, { cssLoader } from '../plugins/css.ts'
13+
import { cssLoader } from '../plugins/css.ts'
1414
import { ensureTextFile, existsDir, existsFile, lazyRemove } from '../shared/fs.ts'
1515
import log, { Measure } from '../shared/log.ts'
1616
import util from '../shared/util.ts'
@@ -194,7 +194,6 @@ export class Aleph implements IAleph {
194194
ms.stop(`init env`)
195195

196196
// apply plugins
197-
cssPlugin().setup(this)
198197
await Promise.all(
199198
this.#config.plugins.map(async plugin => {
200199
await plugin.setup(this)

0 commit comments

Comments
 (0)