mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
feat: generate meaningful chunkNames
This commit is contained in:
parent
3939ea9e4d
commit
aa71b51538
@ -1,5 +1,5 @@
|
|||||||
import Module from 'module'
|
import Module from 'module'
|
||||||
import { dirname, join, resolve } from 'path'
|
import { dirname, join, relative, resolve } from 'path'
|
||||||
import { InputOptions, OutputOptions } from 'rollup'
|
import { InputOptions, OutputOptions } from 'rollup'
|
||||||
import { terser } from 'rollup-plugin-terser'
|
import { terser } from 'rollup-plugin-terser'
|
||||||
import commonjs from '@rollup/plugin-commonjs'
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
@ -50,7 +50,7 @@ export const getRollupConfig = (options: SLSOptions) => {
|
|||||||
'@vue/compiler-ssr'
|
'@vue/compiler-ssr'
|
||||||
]))
|
]))
|
||||||
|
|
||||||
// Uses eval
|
// Uses eval 😈
|
||||||
aliases.depd = '~mocks/custom/depd'
|
aliases.depd = '~mocks/custom/depd'
|
||||||
|
|
||||||
if (options.node === false) {
|
if (options.node === false) {
|
||||||
@ -91,13 +91,28 @@ export const getRollupConfig = (options: SLSOptions) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const chunksDirName = join(dirname(options.outName), 'chunks')
|
const chunksDirName = join(dirname(options.outName), 'chunks')
|
||||||
|
const serverDir = join(options.buildDir, 'dist/server')
|
||||||
|
|
||||||
const rollupConfig: RollupConfig = {
|
const rollupConfig: RollupConfig = {
|
||||||
input: resolvePath(options, options.entry),
|
input: resolvePath(options, options.entry),
|
||||||
output: {
|
output: {
|
||||||
dir: options.targetDir,
|
dir: options.targetDir,
|
||||||
entryFileNames: options.outName,
|
entryFileNames: options.outName,
|
||||||
chunkFileNames: join(chunksDirName, '[name].js'),
|
chunkFileNames (chunkInfo) {
|
||||||
|
let prefix = ''
|
||||||
|
const modules = Object.keys(chunkInfo.modules)
|
||||||
|
const lastModule = modules[modules.length - 1]
|
||||||
|
if (lastModule.startsWith(serverDir)) {
|
||||||
|
prefix = join('ssr', relative(serverDir, dirname(lastModule)))
|
||||||
|
} else if (lastModule.startsWith(options.buildDir)) {
|
||||||
|
prefix = 'ssr'
|
||||||
|
} else if (lastModule.startsWith(options.runtimeDir)) {
|
||||||
|
prefix = 'runtime'
|
||||||
|
} else if (!prefix && options.serverMiddleware.find(m => lastModule.startsWith(m.handle))) {
|
||||||
|
prefix = 'middleware'
|
||||||
|
}
|
||||||
|
return join(chunksDirName, prefix, '[name].js')
|
||||||
|
},
|
||||||
inlineDynamicImports: options.inlineChunks,
|
inlineDynamicImports: options.inlineChunks,
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
exports: 'auto',
|
exports: 'auto',
|
||||||
|
Loading…
Reference in New Issue
Block a user