Giter Site home page Giter Site logo

vue-style-loader's Introduction

vue-style-loader Build Status npm package

This is a fork based on style-loader. Similar to style-loader, you can chain it after css-loader to dynamically inject CSS into the document as style tags. However, since this is included as a dependency and used by default in vue-loader, in most cases you don't need to configure this loader yourself.

Options

  • manualInject (3.1.0+):

    Type: boolean. When importing the style from a non-vue-file, by default the style is injected as a side effect of the import. When manualInject is true, the imported style object exposes a __inject__ method, which can then be called manually at appropriate timing. If called on the server, the method expects one argument which is the ssrContext to attach styles to.

    import styles from 'styles.scss'
    
    export default {
      beforeCreate() { // or create a mixin for this purpose
        if(styles.__inject__) {
          styles.__inject__(this.$ssrContext)
        }
      }
    
      render() {
        return <div class={styles.heading}>Hello World</div>
      }
    }

    Note this behavior is enabled automatically when vue-style-loader is used on styles imported within a *.vue file. The option is only exposed for advanced usage.

  • ssrId (3.1.0+):

    Type: boolean. Add data-vue-ssr-id attribute to injected <style> tags even when not in Node.js. This can be used with pre-rendering (instead of SSR) to avoid duplicate style injection on hydration.

Differences from style-loader

Server-Side Rendering Support

When bundling with target: 'node', the styles in all rendered components are collected and exposed on the Vue render context object as context.styles, which you can simply inline into your markup's <head>. If you are building a Vue SSR app, you probably should use this loader for CSS imported from JavaScript files too.

Misc

  • Does not support url mode and reference counting mode. Also removed singleton and insertAt query options. It always automatically pick the style insertion mechanism that makes most sense. If you need these capabilities you should probably use the original style-loader instead.

  • Fixed the issue that root-relative URLs are interpreted against chrome:// urls and make source map URLs work for injected <style> tags in Chrome.

License

MIT

vue-style-loader's People

Contributors

sokra avatar yyx990803 avatar diurnalist avatar elsbree avatar jounqin avatar spacek33z avatar svenheden avatar tgriesser avatar joshwiens avatar kevinzwhuang avatar shama avatar sirlancelot avatar gryzzly avatar nickdima avatar erictheswift avatar oskarer avatar pi0 avatar thelarkinn avatar simenb avatar taopaic avatar zachlysobey avatar blainekasten avatar johnjacobkenny avatar krrg avatar jhnns avatar zxcabs avatar egoist avatar denisizmaylov avatar verticalpalette avatar 2color avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.