Nuxt/examples/style-resources
2018-08-16 14:48:26 +02:00
..
assets example: Add Less file to show multi pre-processors 2018-01-08 10:41:30 +01:00
pages example: Add Less file to show multi pre-processors 2018-01-08 10:41:30 +01:00
nuxt.config.js feat: rewrite core to esm 2018-03-16 19:42:06 +03:30
package.json refactor: rename examples 2018-03-19 10:41:46 +08:00
README.md updated style-resources-loader to version 1.2.1, added "css" as supported filetype in docs (#3738) 2018-08-16 14:48:26 +02:00

Using build.styleResources with Nuxt.js

This is useful when you need to inject some variables and mixins in your pages without having to import them every time.

Nuxt.js uses https://github.com/yenshih/style-resources-loader to achieve this behaviour.

You need to specify the patterns/path you want to include for the given pre-processors: css, less, sass, scss or stylus

⚠️ You cannot use path aliases here (~ and @), you need to use relative or absolute paths.

nuxt.config.js:

{
  build: {
    styleResources: {
      scss: './assets/variables.scss',
      less: './assets/*.less',
      // sass: ...,
      // scss: ...
      options: {
        // See https://github.com/yenshih/style-resources-loader#options
        // Except `patterns` property
      }
    }
  }
}

⚠️ If you want to use @import in these styleResources files, you should use path alias (~@) like this

@import '~@/assets/other.scss';

Then in your pages, you can use directly:

pages/index.vue

<template>
  <div class="main">
    <p>Page with SCSS</p>
    <p><nuxt-link to="/less">LESS</nuxt-link></p>
  </div>
</template>

<style lang="scss">
/* ~/assets/variables.scss is injected automatically here */
.main {
  background: $main;
}
</style>

Thanks to 0pt1m1z3r for adding this feature and example.