Kumaran S
Kumaran S

Reputation: 131

Use custom SCSS with Bootstrap-Vue + Webpack + Vue.js

I'm creating an application using VueJS with Bootstrap-Vue. I am trying to import SCSS file to override the Bootstrap variables as well as another SCSS for custom styles.

Here is what I have so far:

npm install node-sass sass-loader css-loader --save-dev

{ test:/\.(s*)css$/, use:['style-loader','css-loader', 'sass-loader']}

main.js

import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'
import App from './App'
import router from './router'
import fontawesome from '@fortawesome/fontawesome'
import light from '@fortawesome/fontawesome-pro-light'

Vue.use(BootstrapVue)

Vue.config.productionTip = false

fontawesome.library.add(light)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

<style lang="scss">
  @import './assets/scss/app.scss';
</style>

When I run npm run dev I get the following error:

ERROR  Failed to compile with 1 errors                                                      21:05:54

 error  in ./src/main.js

Syntax Error: Unexpected token, expected ; (29:7)

  27 | })
  28 |
> 29 | <style lang="scss">
     |        ^
  30 |   @import './assets/scss/app.scss';
  31 | </style>
  32 |



 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

    fontawesome.library.add(light)

    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      components: { App },
      template: '<App/>'
    })

    <style lang="scss">
      @import './assets/scss/app.scss';
    </style>

I am not sure why it is not working. I have tried various solutions on Github and Stack Overflow.

Any help would be appreciated.

Upvotes: 4

Views: 7930

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50767

You can't write style tag in javascript like this. You need to either move it to a vue file and attach a loader to it, or use a standard import:

import './assets/scss/app.scss';

Without the style tags or the @ symbol.

Upvotes: 2

Related Questions