Skip to content

Commit 63c1a8d

Browse files
committed
fix: don't panic when code-splitting
1 parent 268b82e commit 63c1a8d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,23 @@ export default (options = {}) => {
103103
async generateBundle(opts, bundle) {
104104
if (extracted.size === 0) return
105105

106+
// TODO: support `[hash]`
106107
const dir = opts.dir || path.dirname(opts.file)
108+
const file =
109+
opts.file ||
110+
path.join(
111+
opts.dir,
112+
Object.keys(bundle).find(fileName => bundle[fileName].isEntry)
113+
)
107114
const getExtracted = () => {
108115
const fileName =
109116
typeof postcssLoaderOptions.extract === 'string' ?
110117
path.relative(dir, postcssLoaderOptions.extract) :
111-
`${path.basename(opts.file, path.extname(opts.file))}.css`
118+
`${path.basename(file, path.extname(file))}.css`
112119
const concat = new Concat(true, fileName, '\n')
113120
const entries = Array.from(extracted.values())
114-
const { modules } = bundle[path.relative(dir, opts.file)]
121+
const { modules } = bundle[path.relative(dir, file)]
122+
115123
if (modules) {
116124
const fileList = Object.keys(modules)
117125
entries.sort(

0 commit comments

Comments
 (0)