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

Commit c3a7f22

Browse files
committed
Fix import map
1 parent 4d7ba19 commit c3a7f22

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

server/app.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ import type {
3434
ServerApplication
3535
} from '../types.ts'
3636
import { VERSION } from '../version.ts'
37-
import { defaultConfig, loadConfig, loadImportMap, RequiredConfig } from './config.ts'
37+
import {
38+
defaultConfig,
39+
defaultImports,
40+
loadConfig,
41+
loadImportMap,
42+
RequiredConfig
43+
} from './config.ts'
3844
import { CSSProcessor } from './css.ts'
3945
import {
4046
computeHash,
@@ -110,7 +116,14 @@ export class Application implements ServerApplication {
110116
])
111117

112118
Object.assign(this.config, config)
113-
Object.assign(this.importMap, importMap)
119+
Object.assign(this.importMap, {
120+
...importMap,
121+
imports: Object.assign(
122+
defaultImports(this.config.react.version),
123+
importMap.imports
124+
)
125+
})
126+
console.log(this.importMap)
114127
this.#pageRouting.config(this.config)
115128
this.#cssProcesser.config(!this.isDev, this.config.css)
116129

server/config.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -152,45 +152,19 @@ export async function loadImportMap(workingDir: string): Promise<ImportMap> {
152152
}
153153
}
154154

155-
// update import map for alephjs dev env
156-
const DEV_PORT = Deno.env.get('ALEPH_DEV_PORT')
157-
if (DEV_PORT) {
158-
const alephPkgUri = getAlephPkgUri()
159-
const imports = {
160-
'aleph/': `${alephPkgUri}/`,
161-
'framework': `${alephPkgUri}/framework/core/mod.ts`,
162-
'framework/react': `${alephPkgUri}/framework/react/mod.ts`,
163-
'react': `https://esm.sh/react@${defaultReactVersion}`,
164-
'react-dom': `https://esm.sh/react-dom@${defaultReactVersion}`,
165-
'react-dom/server': `https://esm.sh/react-dom@${defaultReactVersion}/server`,
166-
}
167-
Object.assign(importMap.imports, imports)
168-
}
169-
170155
return importMap
171156
}
172157

173-
async function loadPostCSSConfig(workingDir: string): Promise<{ plugins: PostCSSPlugin[] }> {
174-
for (const name of Array.from(['ts', 'js', 'json']).map(ext => `postcss.config.${ext}`)) {
175-
const p = join(workingDir, name)
176-
if (existsFileSync(p)) {
177-
let config: any = null
178-
if (name.endsWith('.json')) {
179-
config = JSON.parse(await Deno.readTextFile(p))
180-
} else {
181-
const mod = await import('file://' + p)
182-
config = mod.default
183-
if (util.isFunction(config)) {
184-
config = await config()
185-
}
186-
}
187-
if (isPostcssConfig(config)) {
188-
return config
189-
}
190-
}
158+
export function defaultImports(reactVersion: string): Record<string, string> {
159+
const alephPkgUri = getAlephPkgUri()
160+
return {
161+
'aleph/': `${alephPkgUri}/`,
162+
'framework': `${alephPkgUri}/framework/core/mod.ts`,
163+
'framework/react': `${alephPkgUri}/framework/react/mod.ts`,
164+
'react': `https://esm.sh/react@${reactVersion}`,
165+
'react-dom': `https://esm.sh/react-dom@${reactVersion}`,
166+
'react-dom/server': `https://esm.sh/react-dom@${reactVersion}/server`,
191167
}
192-
193-
return { plugins: ['autoprefixer'] }
194168
}
195169

196170
function isFramework(v: any): v is 'react' {

0 commit comments

Comments
 (0)