Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollup, Vue and Buble, unexpected token in scss file

I am trying to compile SFC with rollup, using Vue and Buble, following the example suplied in the Vue official page. But I keep getting this error:

src/wrapper.js → dist/chat.min.js...
[!] (plugin buble) SyntaxError: Unexpected token (2:0)
src\components\Chat.vue?vue&type=style&index=0&lang.scss (2:0)
1 :
2 : .chat, .chat>*, .chat * {

This is my rollup.config.js:

import commonjs from '@rollup/plugin-commonjs'; // Convert CommonJS modules to ES6
import vue from 'rollup-plugin-vue'; // Handle .vue SFC files
import buble from '@rollup/plugin-buble'; // Transpile/polyfill with reasonable browser support
export default {
    input: 'src/wrapper.js', // Path relative to package.json
    output: {
        name: 'Chat',
        exports: 'named',
    },
    plugins: [
        commonjs(),
        vue({
            css: true, // Dynamically inject css as a <style> tag
            compileTemplate: true, // Explicitly convert template to render function
        }),
        buble(), // Transpile to ES5
    ],
};

And this is my wrapper.js:

  // Import vue component
  import component from "./components/Chat.vue";

  // Declare install function executed by Vue.use()
  export function install(Vue) {
    if (install.installed) return;
    install.installed = true;
    Vue.component("chat", component);
  }

  // Create module definition for Vue.use()
  const plugin = {
    install
  };

  // Auto-install when vue is found (eg. in browser via <script> tag)
  let GlobalVue = null;
  if (typeof window !== "undefined") {
    GlobalVue = window.Vue;
  } else if (typeof global !== "undefined") {
    GlobalVue = global.Vue;
  }
  if (GlobalVue) {
    GlobalVue.use(plugin);
  }

  // To allow use as module (npm/webpack/etc.) export component
  export default component;

I've tried removing buble from the plugins, but I end up with an error saying "Unexpected token (Note that you need plugins to import files that are not JavaScript)"

like image 465
Francisco Garrido Avatar asked Jan 17 '26 06:01

Francisco Garrido


1 Answers

Try this:

$ npm install --save-dev rollup-plugin-scss

In rollup.config.js:

import scss from 'rollup-plugin-scss';      // handles '.css' and '.scss'

plugins: { ..., scss() }

I don't really know what's going on, here. The above worked for me (Vue.js 3 (beta) and rollup-plugin-vue 6.0.0-beta.6.

like image 161
akauppi Avatar answered Jan 20 '26 21:01

akauppi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!