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

CSS Modules: ExtractTextPlugin changes the format of the imported style object #348

Closed
websash opened this issue Jan 21, 2017 · 8 comments
Closed

Comments

@websash
Copy link

websash commented Jan 21, 2017

Been migrating to Webpack 2 and noticed my local CSS is not working with the new ExtractTextPlugin.
Consider this sample code:

import style from './style.css'

const div = document.createElement('div')

div.className = 'foobarGlobal ' + style.foobarLocal

document.body.appendChild(div).textContent = 'css modules'

console.info('style', style)

Without ExtractTextPlugin I got this style:
screen shot 2017-01-21 at 3 32 18 pm
which is fine and expected.

Now when using ExtractTextPlugin I'm getting this format:
screen shot 2017-01-21 at 3 32 39 pm
as if I'm supposed to use style.locals.foobarLocal now. Why is that?
My test webpack config https://github.com/websash/webpack2-css-modules/blob/master/webpack.config.js

@Ephem
Copy link

Ephem commented Jan 24, 2017

+1 I'm experiencing the same issue.

@Ephem
Copy link

Ephem commented Jan 24, 2017

This turned out to be related to #330 for me. Before figuring out what was wrong (I was using use: ExtractTextPlugin({ ... }) instead of loader: ExtractTextPlugin({ ... })) I tried all kinds of configs to get it working. At some point I ended up with the error above, but when I got it working properly, css modules were exported correctly as well.

@websash Maybe you are having some kind of related issue?

This part is from your config:

use: [
  ExtractTextPlugin.extract({
    fallbackLoader: 'style-loader',
    loader: 'css-loader'
  }), {
    loader: 'css-loader',
    options: {
      minimize: true,
      modules: true,
      importLoaders: true,
      localIdentName: '[hash:6]'
    }
  }
],

Maybe something like this would work:

loader: ExtractTextPlugin.extract({
  fallbackLoader: 'style-loader',
  loader: {
    loader: 'css-loader',
    query: {
      minimize: true,
      modules: true,
      importLoaders: true,
      localIdentName: '[hash:6]'
    }
  }
}),

You would have to do the same thing a bit further down in the config. I hope it helps!

@websash
Copy link
Author

websash commented Jan 25, 2017

@Ephem thanx for the tip. Your config is definitely working for me 👍 I was sure I had to use use with an array all the time and options for loader configuration but here we need query 😕 Wish we had better docs

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jan 25, 2017

@websash @Ephem Yep the syntax will definitely be updated/fixed in v2 final. Besides that if CSS Modules work correctly please close the issue 😛

@Ephem
Copy link

Ephem commented Jan 25, 2017

@websash No worries, glad I could help. :) PR #343 fixes this so that we can use use and PR #276 fixes options. I guess this time the docs were correct, but the implementation needed some tweaking. :) I think this issue could be closed now?

@joshwiens
Copy link
Member

#343 has been merged, included in https://github.com/webpack-contrib/extract-text-webpack-plugin/releases/tag/v2.0.0-rc.0 and published to npm as v2.0.0-rc.0

@yinjunok
Copy link

yinjunok commented Jun 6, 2017

@Ephem that's cool, thanks.

@arisunarya
Copy link

@Ephem thanks, that's work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants