npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-esm-to-systemjs

v1.0.1

Published

Vite plugin that transforms ESM output to SystemJS format using Babel

Readme

vite-plugin-esm-to-systemjs

A Vite plugin that transforms ESM output to SystemJS format.

npm version license

📋 Overview

vite-plugin-esm-to-systemjs is a Vite plugin that converts ECMAScript modules (ESM) output to SystemJS format.

Why do you need this plugin?

Starting with Vite 8, the system output format was deprecated, leaving developers who need to generate SystemJS format bundles without native support. This plugin solves that problem by using Babel to automatically transform modules during the build phase.

Common use cases:

  • Micro frontend applications using SystemJS as a module loader
  • Legacy projects that depend on SystemJS format
  • Environments that require dynamic module loading

🚀 Installation

# With pnpm (recommended)
pnpm add -D vite-plugin-esm-to-systemjs

# With npm
npm install --save-dev vite-plugin-esm-to-systemjs

# With yarn
yarn add --dev vite-plugin-esm-to-systemjs

📖 Basic Usage

1. Configure in vite.config.ts

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { vitePluginEsmToSystemjs } from 'vite-plugin-esm-to-systemjs'

export default defineConfig({
  plugins: [
    vue(),
    vitePluginEsmToSystemjs(),
  ],
  build: {
    // Recommended configuration
    rollupOptions: {
      output: {
        format: 'es', // Modules will be output as ESM before being transformed
      }
    }
  }
})

2. Build your project

pnpm build

The plugin will automatically transform all ESM chunks to SystemJS format during the build.

💡 Practical Examples

Example 1: Vue.js Application

// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { vitePluginEsmToSystemjs } from 'vite-plugin-esm-to-systemjs'

export default defineConfig({
  plugins: [
    vue(),
    vitePluginEsmToSystemjs(),
  ],
  build: {
    rollupOptions: {
      output: {
        entryFileNames: '[name].js',
        chunkFileNames: '[name]-[hash].js',
        assetFileNames: 'assets/[name]-[hash][extname]',
      }
    }
  }
})

After compiling, your JavaScript files will be in SystemJS format and can be loaded with:

<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/systemjs@6/dist/system.js"></script>
  <script>
    System.import('./dist/main.js')
  </script>
</head>
<body></body>
</html>

Example 2: Micro Frontend with single-spa

// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { vitePluginEsmToSystemjs } from 'vite-plugin-esm-to-systemjs'

export default defineConfig({
  plugins: [
    react(),
    vitePluginEsmToSystemjs(),
  ],
  build: {
    lib: {
      entry: 'src/index.ts',
      name: 'MyMicroApp',
      fileName: (format) => `my-micro-app.${format === 'es' ? 'js' : 'cjs'}`,
      formats: ['es']
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM'
        }
      }
    }
  }
})

Example 3: Angular Application

// vite.config.ts
import { defineConfig } from 'vite'
import { vitePluginEsmToSystemjs } from 'vite-plugin-esm-to-systemjs'

export default defineConfig({
  plugins: [
    vitePluginEsmToSystemjs(),
  ],
  build: {
    rollupOptions: {
      output: {
        format: 'es',
        entryFileNames: '[name].js',
        chunkFileNames: '[name].js'
      }
    }
  }
})

🔧 How It Works

The plugin:

  1. Applies after the main build (enforce: 'post') - ensures other plugins process first
  2. Transforms each chunk during the rendering phase (renderChunk)
  3. Uses Babel with the following plugins:
    • @babel/plugin-transform-dynamic-import - transforms dynamic import() calls
    • @babel/plugin-transform-modules-systemjs - transforms ESM modules to SystemJS
  4. Preserves source maps for production debugging

⚙️ Configuration Options

The plugin uses Babel's default configuration:

  • Module format: ESM → SystemJS
  • Source maps: Enabled
  • Compact: Disabled (more readable code)

📝 Requirements

  • Vite: >= 5.0.0
  • Node.js: >= 16.0.0

🤝 Dependencies

{
  "@babel/core": "^7.29.7",
  "@babel/plugin-transform-dynamic-import": "^7.29.7",
  "@babel/plugin-transform-modules-systemjs": "^7.29.7"
}

🐛 Troubleshooting

Files are still ESM after build

Make sure:

  • The plugin is included in vite.config.ts
  • The output format in rollupOptions is 'es'
  • You ran pnpm build (not just pnpm dev)

Babel transformation errors

Verify that:

  • You have the correct dependencies installed
  • Your JavaScript code is valid
  • You're not using syntax that Babel cannot transform

Source maps not generated

Make sure your build configuration includes sourcemap: true:

build: {
  sourcemap: true,
  rollupOptions: {
    output: {
      format: 'es'
    }
  }
}

📚 References

📄 License

Apache License 2.0 - see LICENSE for more details.

👤 Author

Alberto Cristancho

📦 Publishing

This package is available on npm.


Found it useful? Consider leaving a ⭐ on GitHub