mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(nitro): raw loader (#75)
This commit is contained in:
parent
8fbefa309e
commit
2d60e71fcb
@ -23,6 +23,7 @@ import { autoMock } from './plugins/automock'
|
||||
import { staticAssets, dirnames } from './plugins/static'
|
||||
import { middleware } from './plugins/middleware'
|
||||
import { esbuild } from './plugins/esbuild'
|
||||
import { raw } from './plugins/raw'
|
||||
|
||||
export type RollupConfig = InputOptions & { output: OutputOptions }
|
||||
|
||||
@ -109,6 +110,9 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
|
||||
rollupConfig.plugins.push(timing())
|
||||
}
|
||||
|
||||
// Raw asset loader
|
||||
rollupConfig.plugins.push(raw())
|
||||
|
||||
// https://github.com/rollup/plugins/tree/master/packages/replace
|
||||
rollupConfig.plugins.push(replace({
|
||||
// @ts-ignore https://github.com/rollup/plugins/pull/810
|
||||
|
20
packages/nitro/src/rollup/plugins/raw.ts
Normal file
20
packages/nitro/src/rollup/plugins/raw.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { extname } from 'upath'
|
||||
import type { Plugin } from 'rollup'
|
||||
|
||||
export interface RawOptions {
|
||||
extensions?: string[]
|
||||
}
|
||||
|
||||
export function raw (opts: RawOptions = {}): Plugin {
|
||||
const extensions = new Set(['.md', '.mdx', '.yml', '.txt', '.css', '.htm', '.html']
|
||||
.concat(opts.extensions || []))
|
||||
|
||||
return {
|
||||
name: 'raw',
|
||||
transform (code, id) {
|
||||
if (id[0] !== '\0' && extensions.has(extname(id))) {
|
||||
return `// ${id}\nexport default ${JSON.stringify(code)}`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user