webpack / docs

[OLD] documentation for webpack
http://webpack.github.io/docs/
1.46k stars 127 forks source link

cannot load css on demand in one single entry #73

Closed edwardfxiao closed 8 years ago

edwardfxiao commented 8 years ago

for maintaining purpose, I have merged several entries into one single entry, and I am using require.ensure([], function(require) {}) to include my js and css file on demand, which looks like:

// common.js
if($('#is_a_page').length) {
 require.ensure(['a.js', 'a.css'], function(require) {
      require('a.js');
      require('a.css');
    });
}
else if($('#is_b_page').length) {
 require.ensure(['b.js', 'b.css'], function(require) {
      require('b.js');
      require('b.css');
    });
}

// a.js
alert('its page A');

// b.js
alert("its page B");
/*a.css*/
body{
  backgroung: #fff;
}

/*b.css*/
body{
  backgroung: #000!important;
}

then on both of page A and page B, I require the common.js and common.css

now, when I visit page A, it alerts "its page A" as expect, and "its page B" alerts on page B as well, everything is perfectly fine, HOWEVER, on both page A and page B, the body's background turns to #000, it seems "require.ensure" only works on separating JS file whereas there is no way to separate two css files. Is that correct? any suggestions?

ecmadao commented 8 years ago

same here, any thoughts??