6

I'm working on an Angular 2 app and currently trying to build it with Webpack 2 (this is my first foray into Webpack).

I understand the difference between style-loader and to-string-loader, the former adds CSS to the DOM, the latter creates a string array for Angular 2 to consume via the styles property.

My question is, can I have both? Or put another way, if I have global styles in a file site.css, what is the proper way to bundle those with Webpack without changing the behavior for component styles (to-string-loader, css-loader)?

Just requiring or importing them in main.ts doesn't seem to be enough for Webpack to figure out what to do.

1 Answer 1

7

Loaders can be overridden for specific module request:

require("!!style!css!./global-styles/site.css");

Or different loaders can be defined for different conditions:

module: {
    loaders: [
        {
            test: /\.css$/,
            include: [path.resolve(__dirname, "global-styles")],
            loaders: ['style', 'css']
        },
        {
            test: /\.css$/,
            exclude: [path.resolve(__dirname, "global-styles")],
            loaders: ['to-string', 'css']
        },
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.