Giter VIP home page Giter VIP logo

to-string-loader's Introduction

to-string loader for webpack

Usage

let output = require('to-string!css!sass!./my.scss');
// => returns sass rendered to CSS a string

Don't forget to polyfill require if you want to use it in node.

See webpack documentation.

Use Case

If you setup a SASS loader:

{
    test: /\.scss$/,
    loaders: [
        'css',
        'sass'
    ]
},

then require('./my.scss') will return an Array object:

0: Array[3]
    0: 223
    1: "html,↵body,↵ol,↵ul,↵li,↵p { margin: 0; padding: 0; }↵"
    2: ""
    length: 3
i: (modules, mediaQuery) { .. }
length: 1
toString: toString()

In some cases (e.g. Angular2 @View styles definition) you need to have style as a string.

You can cast the require output to a string, e.g.

@View({
    directives: [RouterOutlet, RouterLink],
    template: require('./app.html'),
    styles: [
        require('./app.scss').toString()
    ]
})

or you can use to-string loader that will do that for you:

{
    test: /\.scss$/,
    loaders: [
        'to-string',
        'css',
        'sass'
    ]
},

to-string-loader's People

Contributors

3cp avatar dontrelax avatar eugeny avatar gajus avatar seeruk avatar

Watchers

 avatar  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.