N
N
Nikolai Markov2015-07-09 12:32:14
css
Nikolai Markov, 2015-07-09 12:32:14

Is it correct to include styles via webpack?

Now I'm studying webpack and something tells me that including styles directly in the module is not a good idea.
What cons do I see:
- when changing styles, you need to rebuild the bundle again. Is it possible to make sure that the styles are still collected in a separate bundle.css?
- because styles are essentially a js module, then these js modules should be loaded synchronously, while css is loaded asynchronously
What can you say about this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lesha Fedoseev, 2015-07-09
@manameiz

Plugin for saving styles to a separate file: https://github.com/webpack/extract-text-webpack-plugin

_
_ _, 2015-07-09
@AMar4enko

module.exports = {
  cache: true,
  debug: true,
  devtool: 'source-map',
  entry: {
    app: ['./src'],
    style: ['./src/style'],
    vendor: ...

Thus, the style bundle is separated from the rest, and when styles change, only it is rebuilt.
In dev mode, I do not use the extract-text-webpack-plugin plugin, but no one bothers to make separate configurations for dev mode and for the build, and add this plugin in the build.

N
Nikolai Markov, 2015-07-09
@manameiz

And one more question. Let's say we have a SPA. If our main bundle is very large and takes a few seconds to load, do we need to make two of them? The first one is small and light, which only loads the second bundle and shows the spinner at the same time?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question