Skip to content

Commit

Permalink
fix: fix client build entry
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 17, 2022
1 parent 1fcd126 commit 04c4d0f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 63 deletions.
5 changes: 4 additions & 1 deletion src/node/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export async function build(
const appChunk =
clientResult &&
(clientResult.output.find(
(chunk) => chunk.type === 'chunk' && chunk.isEntry
(chunk) =>
chunk.type === 'chunk' &&
chunk.isEntry &&
chunk.facadeModuleId?.endsWith('.js')
) as OutputChunk)

const cssChunk = (
Expand Down
124 changes: 62 additions & 62 deletions src/node/build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,70 +38,70 @@ export async function bundle(
// resolve options to pass to vite
const { rollupOptions } = options

const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => {
// use different entry based on ssr or not
input['app'] = path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js')
return {
root: config.srcDir,
base: config.site.base,
logLevel: 'warn',
plugins: await createVitePressPlugin(
config,
ssr,
pageToHashMap,
clientJSMap
),
ssr: {
noExternal: ['vitepress', '@docsearch/css']
},
build: {
...options,
emptyOutDir: true,
ssr,
outDir: ssr ? config.tempDir : config.outDir,
cssCodeSplit: false,
rollupOptions: {
...rollupOptions,
input,
// important so that each page chunk and the index export things for each
// other
preserveEntrySignatures: 'allow-extension',
output: {
...rollupOptions?.output,
...(ssr
? {
entryFileNames: `[name].js`,
chunkFileNames: `[name].[hash].js`
}
: {
chunkFileNames(chunk) {
// avoid ads chunk being intercepted by adblock
return /(?:Carbon|BuySell)Ads/.test(chunk.name)
? `assets/chunks/ui-custom.[hash].js`
: `assets/chunks/[name].[hash].js`
},
manualChunks(id, ctx) {
// move known framework code into a stable chunk so that
// custom theme changes do not invalidate hash for all pages
if (id.includes('plugin-vue:export-helper')) {
return 'framework'
}
if (
isEagerChunk(id, ctx) &&
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
/vitepress\/dist\/client/.test(id))
) {
return 'framework'
}
}
})
}
const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => ({
root: config.srcDir,
base: config.site.base,
logLevel: 'warn',
plugins: await createVitePressPlugin(
config,
ssr,
pageToHashMap,
clientJSMap
),
ssr: {
noExternal: ['vitepress', '@docsearch/css']
},
build: {
...options,
emptyOutDir: true,
ssr,
outDir: ssr ? config.tempDir : config.outDir,
cssCodeSplit: false,
rollupOptions: {
...rollupOptions,
input: {
...input,
// use different entry based on ssr or not
app: path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js')
},
// minify with esbuild in MPA mode (for CSS)
minify: ssr ? (config.mpa ? 'esbuild' : false) : !process.env.DEBUG
}
// important so that each page chunk and the index export things for each
// other
preserveEntrySignatures: 'allow-extension',
output: {
...rollupOptions?.output,
...(ssr
? {
entryFileNames: `[name].js`,
chunkFileNames: `[name].[hash].js`
}
: {
chunkFileNames(chunk) {
// avoid ads chunk being intercepted by adblock
return /(?:Carbon|BuySell)Ads/.test(chunk.name)
? `assets/chunks/ui-custom.[hash].js`
: `assets/chunks/[name].[hash].js`
},
manualChunks(id, ctx) {
// move known framework code into a stable chunk so that
// custom theme changes do not invalidate hash for all pages
if (id.includes('plugin-vue:export-helper')) {
return 'framework'
}
if (
isEagerChunk(id, ctx) &&
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
/vitepress\/dist\/client/.test(id))
) {
return 'framework'
}
}
})
}
},
// minify with esbuild in MPA mode (for CSS)
minify: ssr ? (config.mpa ? 'esbuild' : false) : !process.env.DEBUG
}
}
})

let clientResult: RollupOutput
let serverResult: RollupOutput
Expand Down

0 comments on commit 04c4d0f

Please sign in to comment.