Skip to content

Commit 584b423

Browse files
committed
fix: fix css split
1 parent 8cff5f4 commit 584b423

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const path = require('path')
34
const split = require('css-split')
45
const { RawSource } = require('webpack-sources')
56
const { interpolateName } = require('loader-utils')
@@ -25,7 +26,7 @@ const strip = (str) => str.replace(/\/$/, '')
2526
* @param {String} input Name to be interpolated.
2627
* @returns {Function} Function to do the interpolating.
2728
*/
28-
const nameInterpolator = (input) => ({file, content, index}) => {
29+
const nameInterpolator = (input) => ({ file, content, index }) => {
2930
const res = interpolateName({
3031
context: '/',
3132
resourcePath: `/${file}`
@@ -51,7 +52,7 @@ const normalizeImports = (input, preserve) => {
5152
if (preserve) {
5253
return nameInterpolator('[name]-split.[ext]')
5354
}
54-
return ({file}) => file
55+
return ({ file }) => file
5556
}
5657
return () => false
5758
default:
@@ -102,6 +103,7 @@ class FastCSSSplitWebpackPlugin {
102103
const input = {
103104
source: asset.source()
104105
}
106+
const dirname = path.dirname(key)
105107
const getName = (i) => this.options.filename(Object.assign({}, asset, {
106108
content: input.source,
107109
file: key,
@@ -111,6 +113,7 @@ class FastCSSSplitWebpackPlugin {
111113
const chunks = split(input.source, this.options.size).map((part, i) => {
112114
const result = new RawSource(part.content)
113115
result.name = getName(i)
116+
result.fullname = dirname && dirname !== '.' ? `${dirname}/${result.name}` : result.name
114117
return result
115118
})
116119

@@ -136,11 +139,11 @@ class FastCSSSplitWebpackPlugin {
136139
}
137140
// Inject the new files into the chunk.
138141
entry.chunks.forEach((file) => {
139-
assets[file.name] = file
140-
chunk.files.push(file.name)
142+
assets[file.fullname] = file
143+
chunk.files.push(file.fullname)
141144
})
142145
const content = entry.chunks.map((file) => {
143-
return `@import "${publicPath}/${file._name}";`
146+
return `@import "${publicPath}/${file.name}";`
144147
}).join('\n')
145148
const imports = this.options.imports(Object.assign({}, entry, {
146149
content

0 commit comments

Comments
 (0)