1

I'm trying to get a Vue project setup with runtime compilation, but I'm not quite sure how to configure this in Snowpack.

Basically currently when I run the project I get a blank screen and the usual "[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".

Currently my files look like below:

snowpack.config.js:

/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
  mount: {
    public: '/',
    src: '/_dist_',
  },
  plugins: [
    '@snowpack/plugin-vue',
    '@snowpack/plugin-dotenv'
  ],
  ...
}

index.js:

import { createApp } from "vue";
// import App from "./App.vue";
import First from "./First.vue";

// const app = createApp(App);
const app = createApp({
  data() {
    return {
      message: 'duck',
    }
  }
});
app.component('first', First);
app.component('ducks', {
  props: ['todo'],
  template: '<li>{{ todo }}</li>'
});
app.mount("#app");


// Hot Module Replacement (HMR) - Remove this snippet to remove HMR.
// Learn more: https://www.snowpack.dev/#hot-module-replacement
if (import.meta.hot) {
  import.meta.hot.accept();
  import.meta.hot.dispose(() => {
    app.unmount();
  });
}

index.html:

...
  <body>
    <div id="app">
      <p>stuff should be fine:</p>
    
      <p>{{message}}</p>
      <ul>
        <li>hello</li>
        <ducks todo="testing"></ducks>
        <ducks todo="goats"></ducks>
        <ducks todo="canoes"></ducks>
      </ul>
    </div>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <script type="module" src="/_dist_/index.js"></script>
  </body>
...

I've tried adding an alias but that doesn't seem to do anything:

snowpack.config.js

module.exports = {
  ...
  plugins: [
    '@snowpack/plugin-vue',
    '@snowpack/plugin-dotenv'
  ]
  ...
  alias: {
    'vue': 'vue/dist/vue.esm-bundler.js'
  }

Anybody know how I can get runtime compilation setup?

Thanks, Matt

Matt H
  • 11
  • 2

1 Answers1

1

I managed to fix this, by using import { createApp, h } from "vue/dist/vue.cjs.prod.js";.

But I'm not sure if this will create other issues in the future.

Ovidiu Dolha
  • 5,335
  • 1
  • 21
  • 30
  • This comment made my day! I’m trying to prototype something and fiddling with webpack is not in my plans. – gnclmorais Mar 04 '21 at 09:28