mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix: addresses static assets/azure issues (#49)
This commit is contained in:
parent
a9b9d19e66
commit
9c25d68511
@ -19,7 +19,7 @@ import { dynamicRequire } from './plugins/dynamic-require'
|
|||||||
import { externals } from './plugins/externals'
|
import { externals } from './plugins/externals'
|
||||||
import { timing } from './plugins/timing'
|
import { timing } from './plugins/timing'
|
||||||
import { autoMock } from './plugins/automock'
|
import { autoMock } from './plugins/automock'
|
||||||
import { staticAssets } from './plugins/static'
|
import { staticAssets, dirnames } from './plugins/static'
|
||||||
import { middleware } from './plugins/middleware'
|
import { middleware } from './plugins/middleware'
|
||||||
import { esbuild } from './plugins/esbuild'
|
import { esbuild } from './plugins/esbuild'
|
||||||
|
|
||||||
@ -128,6 +128,7 @@ export const getRollupConfig = (sigmaContext: SigmaContext) => {
|
|||||||
|
|
||||||
// Static
|
// Static
|
||||||
if (sigmaContext.serveStatic) {
|
if (sigmaContext.serveStatic) {
|
||||||
|
rollupConfig.plugins.push(dirnames())
|
||||||
rollupConfig.plugins.push(staticAssets(sigmaContext))
|
rollupConfig.plugins.push(staticAssets(sigmaContext))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import mime from 'mime'
|
|||||||
import { relative, resolve } from 'upath'
|
import { relative, resolve } from 'upath'
|
||||||
import virtual from '@rollup/plugin-virtual'
|
import virtual from '@rollup/plugin-virtual'
|
||||||
import globby from 'globby'
|
import globby from 'globby'
|
||||||
|
import type { Plugin } from 'rollup'
|
||||||
import type { SigmaContext } from '../../context'
|
import type { SigmaContext } from '../../context'
|
||||||
|
|
||||||
export function staticAssets (context: SigmaContext) {
|
export function staticAssets (context: SigmaContext) {
|
||||||
@ -29,14 +30,12 @@ export function staticAssets (context: SigmaContext) {
|
|||||||
return virtual({
|
return virtual({
|
||||||
'~static-assets': `export default ${JSON.stringify(assets, null, 2)};`,
|
'~static-assets': `export default ${JSON.stringify(assets, null, 2)};`,
|
||||||
'~static': `
|
'~static': `
|
||||||
import { readFile } from 'fs/promises'
|
import { promises } from 'fs'
|
||||||
import { resolve, dirname } from 'path'
|
import { resolve } from 'path'
|
||||||
import assets from '~static-assets'
|
import assets from '~static-assets'
|
||||||
|
|
||||||
const mainDir = dirname(require.main.filename)
|
|
||||||
|
|
||||||
export function readAsset (id) {
|
export function readAsset (id) {
|
||||||
return readFile(resolve(mainDir, getAsset(id).path))
|
return promises.readFile(resolve(mainDir, getAsset(id).path))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAsset (id) {
|
export function getAsset (id) {
|
||||||
@ -45,3 +44,12 @@ export function getAsset (id) {
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dirnames (): Plugin {
|
||||||
|
return {
|
||||||
|
name: 'dirnames',
|
||||||
|
renderChunk (code, chunk) {
|
||||||
|
return code + (chunk.isEntry ? 'global.mainDir="undefined"!=typeof __dirname?__dirname:require.main.filename;' : '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user