diff --git a/packages/meta/src/module.ts b/packages/meta/src/module.ts index 09c8cc0f2f..51b5340114 100644 --- a/packages/meta/src/module.ts +++ b/packages/meta/src/module.ts @@ -12,7 +12,7 @@ export default defineNuxtModule({ const runtimeDir = resolve(__dirname, 'runtime') // Transpile @nuxt/meta - nuxt.options.build.transpile.push('@nuxt/meta', runtimeDir) + nuxt.options.build.transpile.push('@nuxt/meta', runtimeDir, '@vueuse/head') nuxt.options.alias['@nuxt/meta'] = resolve(runtimeDir, 'index') // Global meta diff --git a/packages/nitro/src/compat.ts b/packages/nitro/src/compat.ts index 83c4278382..90ae7aa0bf 100644 --- a/packages/nitro/src/compat.ts +++ b/packages/nitro/src/compat.ts @@ -1,6 +1,6 @@ import fetch from 'node-fetch' import { resolve } from 'upath' -import { readFile, writeFile } from 'fs-extra' +import { move, readFile, writeFile } from 'fs-extra' import { build, generate, prepare } from './build' import { getNitroContext, NitroContext } from './context' import { createDevServer } from './server/dev' @@ -78,7 +78,9 @@ export default function nuxt2CompatModule () { // Generate mjs resources nuxt.hook('build:compiled', async ({ name }) => { if (name === 'server') { - await writeFile(resolve(nuxt.options.buildDir, 'dist/server/server.mjs'), 'export { default } from "./server.js"', 'utf8') + const jsServerEntry = resolve(nuxt.options.buildDir, 'dist/server/server.js') + await move(jsServerEntry, jsServerEntry.replace(/.js$/, '.cjs')) + await writeFile(jsServerEntry.replace(/.js$/, '.mjs'), 'export { default } from "./server.cjs"', 'utf8') } else if (name === 'client') { const manifest = await readFile(resolve(nuxt.options.buildDir, 'dist/server/client.manifest.json'), 'utf8') await writeFile(resolve(nuxt.options.buildDir, 'dist/server/client.manifest.mjs'), 'export default ' + manifest, 'utf8') diff --git a/packages/nitro/src/rollup/config.ts b/packages/nitro/src/rollup/config.ts index 0a119cd368..8556430a3e 100644 --- a/packages/nitro/src/rollup/config.ts +++ b/packages/nitro/src/rollup/config.ts @@ -163,7 +163,10 @@ export const getRollupConfig = (nitroContext: NitroContext) => { inline: nitroContext.node === false || nitroContext.inlineDynamicImports, globbyOptions: { ignore: [ - 'server.js' + 'client.manifest.mjs', + 'server.cjs', + 'server.mjs', + 'server.manifest.mjs' ] } })) diff --git a/packages/nitro/src/rollup/plugins/dynamic-require.ts b/packages/nitro/src/rollup/plugins/dynamic-require.ts index 758907f2ba..7182ff4747 100644 --- a/packages/nitro/src/rollup/plugins/dynamic-require.ts +++ b/packages/nitro/src/rollup/plugins/dynamic-require.ts @@ -53,7 +53,7 @@ export function dynamicRequire ({ dir, globbyOptions, inline }: Options): Plugin } // Scan chunks - const files = await globby('**/*.js', { cwd: dir, absolute: false, ...globbyOptions }) + const files = await globby('**/*.{cjs,mjs,js}', { cwd: dir, absolute: false, ...globbyOptions }) const chunks = files.map(id => ({ id, src: resolve(dir, id).replace(/\\/g, '/'), diff --git a/packages/webpack/src/configs/server.ts b/packages/webpack/src/configs/server.ts index 140b883017..08173b3b7d 100644 --- a/packages/webpack/src/configs/server.ts +++ b/packages/webpack/src/configs/server.ts @@ -21,7 +21,7 @@ export function server (ctx: WebpackConfigContext) { function serverPreset (ctx: WebpackConfigContext) { const { config } = ctx - config.output.filename = 'server.js' + config.output.filename = 'server.cjs' config.devtool = 'cheap-module-source-map' config.optimization = { diff --git a/packages/webpack/src/plugins/vue/server.ts b/packages/webpack/src/plugins/vue/server.ts index 89075e8fce..f2c1072cc5 100644 --- a/packages/webpack/src/plugins/vue/server.ts +++ b/packages/webpack/src/plugins/vue/server.ts @@ -82,7 +82,7 @@ export default class VueSSRServerPlugin { } // TODO: Workaround for webpack - const serverJS = 'export { default } from "./server.js"' + const serverJS = 'export { default } from "./server.cjs"' assets['server.mjs'] = { source: () => serverJS, map: () => null, diff --git a/packages/webpack/src/plugins/vue/util.ts b/packages/webpack/src/plugins/vue/util.ts index 6ce85fc9c6..d419f11e93 100644 --- a/packages/webpack/src/plugins/vue/util.ts +++ b/packages/webpack/src/plugins/vue/util.ts @@ -23,7 +23,7 @@ export const validate = (compiler) => { } } -const isJSRegExp = /\.js(\?[^.]+)?$/ +const isJSRegExp = /\.[cm]?js(\?[^.]+)?$/ export const isJS = file => isJSRegExp.test(file) diff --git a/packages/webpack/src/presets/node.ts b/packages/webpack/src/presets/node.ts index 2a188edf3b..9f515e0dd1 100644 --- a/packages/webpack/src/presets/node.ts +++ b/packages/webpack/src/presets/node.ts @@ -10,8 +10,10 @@ export function node (ctx: WebpackConfigContext) { config.output = { ...config.output, - chunkFilename: '[name].js', - libraryTarget: 'commonjs2' + chunkFilename: '[name].cjs', + library: { + type: 'commonjs2' + } } config.performance = {