Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Make extract-text-webpack-plugin re-entrant #17

Closed
andreypopp opened this issue Sep 15, 2014 · 5 comments · Fixed by #18
Closed

Make extract-text-webpack-plugin re-entrant #17

andreypopp opened this issue Sep 15, 2014 · 5 comments · Fixed by #18

Comments

@andreypopp
Copy link
Contributor

I'm working on React Style (see experimental branch and also #8 is slightly related as I iterated form your suggestion).

TL;DR: it produces CSS from JS:

var ReactStyle = require('react-style')

var style = ReactStyle({
  color: 'red',
  backgroundColor: 'white'
})

Becomes:

.automatically_generated_class_name {
  color: 'red';
  background-color: 'white';
}

.
The problem arises when I use both css-loader and react-style-loader with extract-text-webpack-plugin (I need to combine both approaches b/c some legacy styles I still want to import via CSS modules, like bootstrap for example).

Because plugin compiles mini-bundle which includes all JS code (due to react-style-loader) it encounters css requires once more but b/c child compiler has no extract-text-webpack-plugin configured for itself but inherits all loaders from main compiler it fails. But more importantly I don't want to process CSS files during react style bundle compilation b/c such CSS files will be processed by another child compiler (a direct child of main compiler).

So my question is how to make/configure extract-text-webpack-plugin re-entrant so child compilers don't produce another child compilers.

@sokra
Copy link
Member

sokra commented Sep 15, 2014

Try this:

At this line add something like:

    childCompiler.plugin("this-compilation", function(compilation) {
        childCompiler.plugin("normal-module-loader", function(loaderContext, module) {
            loaderContext[__dirname] = false;
        });
    });

and at this line add something like:

if(this[__dirname] === false) {
  return "";
} else 

So it generate an empty module for nested appliance of the extract-text-plugin loader.

andreypopp added a commit to andreypopp/extract-text-webpack-plugin that referenced this issue Sep 15, 2014
This disallows spawning child compilers from a child compiler. Fixes webpack-contrib#17.
@andreypopp
Copy link
Contributor Author

@sokra thank you, this works, I initially fixed it by checking for this[__dirname] === undefined but setting explicitly false makes it more robust.

@sokra
Copy link
Member

sokra commented Sep 15, 2014

The check this[__dirname] === undefined may be useful too to indicate that the user forgot the add the plugin to the plugins array. Could you add an exception for this case to your PR?

@andreypopp
Copy link
Contributor Author

@sokra added

@andreypopp
Copy link
Contributor Author

Would be nice to have a release of the plugin after this PR is merged!

@sokra sokra closed this as completed in #18 Sep 15, 2014
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants