Css-loader: Global and Local css mixed, how to exclude only one directory?

Created on 11 Apr 2016  路  3Comments  路  Source: webpack-contrib/css-loader

My project is dependent on a package called my-package and it has one directory with global css and all others css-modules enabled, how to configure the loader?

The file structure like this.

webpack.config.js
node_modules
鈹斺攢my-package
     鈹斺攢 src
            鈹溾攢styles    (css should be global here)
            鈹溾攢 Component1   (css should be local here)
            鈹溾攢 Component2
            鈹溾攢 Component3

I want to make all styles in src/styles global while others with css-modules. I try to config like this:

    loaders: [{
      test: /\.scss$/,
      include: fs.realpathSync('./node_modules/my-package/src')
      exclude: fs.realpathSync('./node_modules/my-package/src/styles')
      loader: cssModulesLoader,
    }, {
      test: /\.scss$/,
      include: fs.realpathSync('./node_modules/my-package/src/styles')
      loader: globalCssLoader
    }]

What I want is include all the directory first and exclude one sub-directory, but the include and exclude does not work, how to configure for this, thanks.

Most helpful comment

My code above works right. it will include all subdirectory except for styles

include: fs.realpathSync('./node_modules/my-package/src')
exclude: fs.realpathSync('./node_modules/my-package/src/styles')

All 3 comments

Closed as include and exclude works as expected actually.

hey @camsong - trying to get a similar situation working locally. Any way you can provide a gist of your solution?

My code above works right. it will include all subdirectory except for styles

include: fs.realpathSync('./node_modules/my-package/src')
exclude: fs.realpathSync('./node_modules/my-package/src/styles')
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cuiyue picture cuiyue  路  3Comments

jonathanong picture jonathanong  路  3Comments

heldrida picture heldrida  路  4Comments

Naspo88 picture Naspo88  路  3Comments

osenvosem picture osenvosem  路  4Comments