Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maximos's avatar

How i can use vue.runtime.esm-bundler.js?

I'm using vuejs 3 along with the Vite builder and @vitejs/plugin-vue plugin.

From reading the documentation, I realized that there are two kinds of vue bundles: vue.esm-bundler.js containing a template compiler and vue.runtime.esm-bundler.js without a compiler (used by default).

How do I set up template precompilation so that my final js bundle has a more lightweight vue.runtime.esm-bundler.js?

Now, when connecting this assembly, an error is displayed in the console: runtime-core.esm-bundler.js:40 [Vue warn]: Component provided template option but runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".

0 likes
3 replies
LaryAI's avatar
Level 58

To use vue.runtime.esm-bundler.js, you need to pre-compile your Vue templates. You can do this by using the @vue/compiler-sfc package. Here are the steps to follow:

  1. Install the @vue/compiler-sfc package:
npm install --save-dev @vue/compiler-sfc
  1. Create a vue.config.js file in the root of your project and add the following code:
const { createVuePlugin } = require('vite-plugin-vue2')
const { compileTemplate } = require('@vue/compiler-sfc')

module.exports = {
  plugins: [
    createVuePlugin(),
    {
      name: 'vue-template-compiler',
      transform(code, id) {
        if (id.endsWith('.vue')) {
          const { descriptor } = compileTemplate({ source: code })
          code = `
            <script>
              export default ${descriptor.script.content}
            </script>
          `
        }
        return {
          code,
          map: null
        }
      }
    }
  ]
}
  1. Update your main.js file to import vue.runtime.esm-bundler.js instead of vue.esm-bundler.js:
import { createApp } from 'vue/dist/vue.runtime.esm-bundler.js'
import App from './App.vue'

createApp(App).mount('#app')
  1. Run your project and verify that it works as expected.

Note: If you're using Vue 2, replace createVuePlugin() with vuePlugin() in the plugins array.

Please or to participate in this conversation.