0

Normally I use

{ test: /\.sass$/, loader: 'style!css!sass?indentedSyntax' }

and then in main.js

require('./styles.sass')

But it applies style using javascript when main.js is loaded. The problem is that my app us isomorphic and returns some html initially. Because I load main.js just before </body> tag, then styles are applied to document a bit too late (user sees not-styled HTML for a moment).

Therefore I would like to generate regular css file from styles.sass and then simply include id in <head></head> to make sure it is loaded initially. How I can generate regular css file?

I tried:

entry: {
  styles: path.resolve(__dirname, 'app/styles.sass')
}

but it generates styles.js instead of .css file. Moreover if I include styles.js in a head then I get following error in console from styles.js:

Uncaught ReferenceError: webpackJsonp is not defined

2 Answers 2

1

Use the extract text plugin.

Put this in your loaders:

{ test: /\.scss$/, loader: ExtractTextPlugin.extract("css!sass") }

...and in your plugins:

plugins: [
  new ExtractTextPlugin("styles.css")
]

Adapted from...

http://webpack.github.io/docs/stylesheets.html#separate-css-bundle

Sign up to request clarification or add additional context in comments.

Comments

0

When I use Sass in my projects, I in most cases use the same file structure. At least when it comes to the css-folder.

├── index.html
├── /css 
│   ├── style.css
│   ├── /sass
│   ├───── style.scss
│   ├───── ...

In the public folder where I tend to put my js, css and images folder, I always make a batch file. Something like this:

cd "`dirname "$0"`"
sudo sass --watch css/sass:css

This works for all my projects. I just run it and minimize the window. This looks for changes and converts Sass to regular css to the style.cssfile. Then in my index.html I just include css/style.css.

Hope this helps you

1 Comment

But I want it to be handled by webpack actually.

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.