Skip to content

Export output as a string #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gajus opened this issue Jul 17, 2015 · 1 comment
Closed

Export output as a string #108

gajus opened this issue Jul 17, 2015 · 1 comment

Comments

@gajus
Copy link

gajus commented Jul 17, 2015

I am using CSS loader in combination with sass-loader as such:

var webpack = require('webpack');

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

I want require('./my-style.scss') to return a string. However, now it is returning 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()

I can cast the require statement to a string (require('./my-style.scss').toString()), though I'd webpack to do that for me.

How do I modify the loader definition to produce a string as the final output?

@gajus
Copy link
Author

gajus commented Jul 17, 2015

It was an issue with the css-loader. css-loader is returning an Array object. I have written a small loader that casts object to a string, [to-string][https://github.com/gajus/to-string].

It is a simple loader that executes content like a module and casts output to a string:

/**
 * @see https://github.com/webpack/webpack/wiki/Loader-Specification
 */
module.exports = function (content) {
    return 'module.exports = ' + JSON.stringify(this.exec(content, this.resource).toString());
};

For reference http://stackoverflow.com/questions/31474515/how-to-cast-loader-output-to-a-string/31475687.

@gajus gajus closed this as completed Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant