Skip to content

Add ability to output as .mjs file #118

Description

@dennisameling

I have "type": "module" set in my package.json, and I'd like to output my app as an .mjs file. However, when I set outputFormat: 'esm' in this app, it builds with the regular .js extension. This means that when I'm packaging my app as ZIP for AWS Lambda, I have to copy the package.json file into it (using the vite-plugin-static-copy plugin), so that Node understands that it should handle the dist/main.js file as an ESM file instead of CommonJS.

It'd be great if the generated file could use the .mjs file extension, so that I don't have to add the package.json file into my ZIP.

Here's my current vite.config.ts:

import { defineConfig } from 'vitest/config'
import tsconfigPaths from 'vite-tsconfig-paths'
import { VitePluginNode } from "vite-plugin-node";
import { viteStaticCopy } from "vite-plugin-static-copy";

export default defineConfig({
    plugins: [
        tsconfigPaths(),
        ...VitePluginNode({
            adapter: 'express',
            appPath: './src/main.ts',
            exportName: 'myApp',
            outputFormat: 'esm'
        }),
        viteStaticCopy({
            targets: [
                {
                    src: 'package.json',
                    dest: '.'
                }
            ]
        })
    ],
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions