diff --git a/packages/nitro/src/nuxt-deploy.ts b/packages/nitro/src/cli.ts similarity index 87% rename from packages/nitro/src/nuxt-deploy.ts rename to packages/nitro/src/cli.ts index 07d6190b4c..b048857b45 100644 --- a/packages/nitro/src/nuxt-deploy.ts +++ b/packages/nitro/src/cli.ts @@ -7,10 +7,10 @@ import { existsSync, copy, emptyDir } from 'fs-extra' import prettyBytes from 'pretty-bytes' import gzipSize from 'gzip-size' import chalk from 'chalk' -import { getRollupConfig } from './rollup.config' +import { getRollupConfig } from './rollup/config' import { tryImport, hl, prettyPath, compileTemplateToJS, renderTemplate } from './utils' -async function main () { +async function _runCLI () { const rootDir = resolve(process.cwd(), process.argv[2] || '.') // Config @@ -26,7 +26,7 @@ async function main () { logStartup: true } - Object.assign(config, tryImport(rootDir, './nuxt.config')!.deploy) + Object.assign(config, tryImport(rootDir, './nuxt.config')!.serverless) config.buildDir = resolve(config.rootDir, config.buildDir || '.nuxt') @@ -63,13 +63,19 @@ async function main () { consola.info(`Generating bundle for ${hl(target.target)}`) + const _targetDefaults = tryImport(__dirname, `./targets/${target.target}`) || tryImport(config.rootDir, target.target) + if (!_targetDefaults) { + consola.warn('Cannot resolve target', target.target) + continue + } + const _config: any = defu( // Target specific config by user target, // Global user config config, // Target defaults - tryImport(__dirname, `./targets/${target.target}`) || tryImport(config.rootDir, target.target), + _targetDefaults, // Generic defaults { outDir: resolve(config.buildDir, `dist/${target.target}`), outName: 'index.js' } ) @@ -109,7 +115,9 @@ async function main () { } } -main().catch((err) => { - consola.error(err) - process.exit(1) -}) +export function runCLI () { + _runCLI().catch((err) => { + consola.error(err) + process.exit(1) + }) +} diff --git a/packages/nitro/src/index.ts b/packages/nitro/src/index.ts new file mode 100644 index 0000000000..876cc40e6e --- /dev/null +++ b/packages/nitro/src/index.ts @@ -0,0 +1 @@ +export { runCLI } from './cli' diff --git a/packages/nitro/src/rollup.config.ts b/packages/nitro/src/rollup/config.ts similarity index 95% rename from packages/nitro/src/rollup.config.ts rename to packages/nitro/src/rollup/config.ts index 27fa87e2b4..5782bab352 100644 --- a/packages/nitro/src/rollup.config.ts +++ b/packages/nitro/src/rollup/config.ts @@ -83,10 +83,10 @@ export const getRollupConfig = (config) => { const renderer = config.renderer || (config.nuxt === 2 ? 'vue2' : 'vue3') options.plugins.push(alias({ entries: { - '~runtime': path.resolve(__dirname, 'runtime'), - '~renderer': require.resolve('./runtime/' + renderer), + '~runtime': path.resolve(__dirname, '../runtime'), + '~renderer': require.resolve('../runtime/' + renderer), '~build': config.buildDir, - '~mock': require.resolve('./runtime/mock'), + '~mock': require.resolve('../runtime/mock'), ...mocks.reduce((p, c) => ({ ...p, [c]: '~mock' }), {}) } })) diff --git a/packages/nitro/src/dynamic-require.ts b/packages/nitro/src/rollup/dynamic-require.ts similarity index 100% rename from packages/nitro/src/dynamic-require.ts rename to packages/nitro/src/rollup/dynamic-require.ts diff --git a/packages/nitro/src/targets/vercel/index.ts b/packages/nitro/src/targets/vercel/index.ts index 74824ee1fd..0fc011f944 100644 --- a/packages/nitro/src/targets/vercel/index.ts +++ b/packages/nitro/src/targets/vercel/index.ts @@ -5,7 +5,7 @@ export default { dynamicImporter: false, hooks: { 'done' () { - consola.info('Run `vercel deploy` to deploy!') + consola.info('Run `vercel serverless` to serverless!') } } }