diff --git a/src/index.js b/src/index.js index 0bcfb3ba..d17322c7 100644 --- a/src/index.js +++ b/src/index.js @@ -52,6 +52,13 @@ class CssModule extends webpack.Module { return `css ${requestShortener.shorten(this._identifier)}${this._identifierIndex ? ` (${this._identifierIndex})` : ''}`; } + nameForCondition() { + const resource = this._identifier.split('!').pop(); + const idx = resource.indexOf('?'); + if (idx >= 0) return resource.substr(0, idx); + return resource; + } + build(options, compilation, resolver, fileSystem, callback) { this.buildInfo = {}; this.buildMeta = {}; diff --git a/test/cases/split-chunks/expected/main.css b/test/cases/split-chunks/expected/main.css new file mode 100644 index 00000000..aea53e43 --- /dev/null +++ b/test/cases/split-chunks/expected/main.css @@ -0,0 +1,2 @@ +body { background: red; } + diff --git a/test/cases/split-chunks/expected/vendors~main.css b/test/cases/split-chunks/expected/vendors~main.css new file mode 100644 index 00000000..887f3bc1 --- /dev/null +++ b/test/cases/split-chunks/expected/vendors~main.css @@ -0,0 +1,5 @@ +/* This could be bootstrap.css */ +body { + background: green; +} + diff --git a/test/cases/split-chunks/index.js b/test/cases/split-chunks/index.js new file mode 100644 index 00000000..c83e204a --- /dev/null +++ b/test/cases/split-chunks/index.js @@ -0,0 +1,2 @@ +import 'bootstrap.css'; +import './style.css'; diff --git a/test/cases/split-chunks/node_modules/bootstrap.css b/test/cases/split-chunks/node_modules/bootstrap.css new file mode 100644 index 00000000..223c4d00 --- /dev/null +++ b/test/cases/split-chunks/node_modules/bootstrap.css @@ -0,0 +1,4 @@ +/* This could be bootstrap.css */ +body { + background: green; +} diff --git a/test/cases/split-chunks/style.css b/test/cases/split-chunks/style.css new file mode 100644 index 00000000..31fc5b8a --- /dev/null +++ b/test/cases/split-chunks/style.css @@ -0,0 +1 @@ +body { background: red; } diff --git a/test/cases/split-chunks/webpack.config.js b/test/cases/split-chunks/webpack.config.js new file mode 100644 index 00000000..d276ab14 --- /dev/null +++ b/test/cases/split-chunks/webpack.config.js @@ -0,0 +1,32 @@ +const Self = require('../../../'); + +module.exports = { + entry: './index.js', + module: { + rules: [ + { + test: /\.css$/, + use: [ + Self.loader, + 'css-loader', + ], + }, + ], + }, + optimization: { + splitChunks: { + chunks: 'all', + cacheGroups: { + vendors: { + test: /node_modules/, + enforce: true + } + } + } + }, + plugins: [ + new Self({ + filename: '[name].css', + }), + ], +};