to-string-loader
to-string loader for webpack
Last updated 9 months ago by gajus .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install to-string-loader 
SYNC missed versions from official npm registry.

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'
    ]
},

Current Tags

  • 1.1.6                                ...           latest (9 months ago)

8 Versions

  • 1.1.6                                ...           9 months ago
  • 1.1.5                                ...           4 years ago
  • 1.1.4                                ...           4 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 3
This Week 220
This Month 954
Last Day 217
Last Week 665
Last Month 1,648
Dependencies (1)
Dev Dependencies (0)
None
Dependents (127)

Copyright 2014 - 2016 © taobao.org |