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

Commit 2facb19

Browse files
author
Wenjie Xia
committed
fix: fix fixImportUrl method
1 parent ad881a6 commit 2facb19

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

server/app.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export class Appliaction {
5252
plugins: [],
5353
postcss: {
5454
plugins: [
55-
'postcss-nested',
5655
'autoprefixer'
5756
]
5857
}
@@ -581,20 +580,22 @@ export class Appliaction {
581580
await this.createMainModule()
582581

583582
// pre-compile framework modules
584-
const rendererUrl = `${alephPkgUrl}/framework/${this.config.framework}/renderer.ts`
585-
await this.compile(rendererUrl)
586583
if (this.isDev) {
587584
const mods = ['hmr.ts', 'nomodule.ts']
588585
for (const mod of mods) {
589586
await this.compile(`${alephPkgUrl}/framework/core/${mod}`)
590587
}
591588
}
592589

593-
// import framework renderer
594-
const { render } = await import('file://' + this.#modules.get(rendererUrl)!.jsFile)
595-
this.#renderer = { render }
590+
// compile and import framework renderer when ssr is enable
591+
if (this.config.ssr) {
592+
const rendererUrl = `${alephPkgUrl}/framework/${this.config.framework}/renderer.ts`
593+
await this.compile(rendererUrl)
594+
const { render } = await import('file://' + this.#modules.get(rendererUrl)!.jsFile)
595+
this.#renderer = { render }
596+
}
596597

597-
// apply plugins
598+
// apply server plugins
598599
for (const plugin of this.config.plugins) {
599600
if (plugin.type === 'server') {
600601
await plugin.onInit(this)
@@ -764,39 +765,34 @@ export class Appliaction {
764765
/** fix import url */
765766
private fixImportUrl(importUrl: string): string {
766767
const isRemote = util.isLikelyHttpURL(importUrl)
767-
const url = new URL(isRemote ? importUrl : 'file://' + importUrl)
768-
let ext = path.extname(url.pathname) || '.js'
769-
let pathname = util.trimSuffix(url.pathname, ext)
770768
if (isRemote) {
771-
let ok = [...pageModuleExts, 'css', 'pcss'].includes(ext)
772-
if (!ok) {
769+
const url = new URL(importUrl)
770+
let pathname = url.pathname
771+
let ok = [...pageModuleExts, 'css', 'pcss'].includes(path.extname(pathname).slice(1))
772+
if (ok) {
773773
for (const plugin of this.config.plugins) {
774-
if (plugin.type === 'loader' && plugin.test.test(url.pathname)) {
774+
if (plugin.type === 'loader' && plugin.test.test(pathname)) {
775775
ok = true
776776
break
777777
}
778778
}
779779
}
780780
if (!ok) {
781-
ext = '.js'
781+
pathname += '.js'
782+
}
783+
let search = Array.from(url.searchParams.entries()).map(([key, value]) => value ? `${key}=${value}` : key)
784+
if (search.length > 0) {
785+
pathname += '_' + search.join(',')
782786
}
783-
}
784-
let search = Array.from(url.searchParams.entries()).map(([key, value]) => value ? `${key}=${value}` : key)
785-
if (search.length > 0) {
786-
pathname += '_' + search.join(',')
787-
}
788-
if (isRemote) {
789787
return [
790788
'/-/',
791789
(url.protocol === 'http:' ? 'http_' : ''),
792790
url.hostname,
793791
(url.port ? '_' + url.port : ''),
794-
pathname,
795-
ext
792+
pathname
796793
].join('')
797794
}
798-
const result = pathname + ext
799-
return !isRemote && importUrl.startsWith('/api/') ? decodeURI(result) : result
795+
return importUrl
800796
}
801797

802798
/** preprocess css with postcss plugins */
@@ -822,7 +818,7 @@ export class Appliaction {
822818
this.#postcssReady = true
823819
}
824820
if (t !== null) {
825-
log.debug(`load ${this.config.postcss.plugins.length} plugins of postcss in ${Math.round(performance.now() - t)}ms`)
821+
log.debug(`${this.config.postcss.plugins.length} postcss plugins loaded in ${Math.round(performance.now() - t)}ms`)
826822
}
827823
const pcss = (await postcss(this.config.postcss.plugins.map(p => {
828824
if (typeof p === 'string') {

0 commit comments

Comments
 (0)