insin / nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
Other
5.57k stars 332 forks source link

Useable style loader does not work after build #343

Closed kirill-konshin closed 7 years ago

kirill-konshin commented 7 years ago

This issue is a:

NWB version is 0.18.6.

If NWB is used with useable styles loader it works well in dev mode but throws an error if build is served.

Setup:

nwb.config.js

module.exports = {
    type: 'react-app',
    webpack: {
        rules: {
            'sass-style': {
                loader: 'style-loader/useable'
            }
        }
    }
};

src/index.js

import React from "react";
import {render} from "react-dom";
import style from "./index.scss";

style.use(); // <----- this line will produce error in build version

const App = () => (<div>Foo</div>);
render(<App/>, document.getElementById('app'));

src/index.scss

body {
    color: red;
}

Steps to reproduce:

  1. Build
  2. Serve as static
  3. Open browser
  4. Observe error: index.js:6 Uncaught TypeError: t.n(...).a.use is not a function
insin commented 7 years ago

nwb uses ExtractTextPlugin to extract CSS in builds.

According to these issues you can't extract usable styles:

If you need to disable use of ExtractTextPlugin in builds, I could add setting webpack.extractText config to false as a way of disabling it.

kirill-konshin commented 7 years ago

you can't extract usable styles

Totally makes sense

Previously it used to work w/o extra config... but if you can add a way of disabling this, please go ahead.

I think that webpack.extractText: false|null should be just enough: a strict check that if it's defined and is falsy then disable the plugin, but undefined will just use default config.

insin commented 7 years ago

If it used to work and the stylesheet was in a split chunk you could try webpack.extractText = {allChunks: false} config - the default was changed to true a while back to avoid pulling the style-loader runtime into every build.

kirill-konshin commented 7 years ago

Yep, that's the case, it is working with allChunks: false. That's a very bad change, it's backward incompatible... I understand the rationale, but still...

In any case, I hope to see a setting to completely disable the extract text plugin because for useable styles case it is useless.

kirill-konshin commented 7 years ago

What will be the ETA of change?

kirill-konshin commented 7 years ago

Fix confirmed.