Skip to content

Commit bb9a7ab

Browse files
committed
feat: emitAsset pass relative string path
1 parent 1006abf commit bb9a7ab

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

packages/unplugin-tailwindcss-mangle/src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
9393
webpack(compiler) {
9494
const Compilation = compiler.webpack.Compilation
9595
const { ConcatSource } = compiler.webpack.sources
96-
96+
function getEmitAssetPath(outputPath: string, file: string) {
97+
return path.relative(compiler.context, path.resolve(outputPath, file))
98+
}
9799
compiler.hooks.compilation.tap(pluginName, (compilation) => {
98100
compilation.hooks.processAssets.tap(
99101
{
@@ -122,11 +124,14 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
122124
groupedEntries.js.forEach(([file, source]) => {
123125
js.set(file, source)
124126
})
125-
outputCachedMap.set(compiler.outputPath, {
126-
css,
127-
html,
128-
js
129-
})
127+
if (js.size || css.size || html.size) {
128+
outputCachedMap.set(compiler.outputPath, {
129+
css,
130+
html,
131+
js
132+
})
133+
}
134+
130135
return
131136
}
132137

@@ -149,7 +154,7 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
149154
runtimeSet
150155
})
151156
const source = new ConcatSource(html)
152-
compilation.emitAsset(path.resolve(key, file), source)
157+
compilation.emitAsset(getEmitAssetPath(key, file), source)
153158
})
154159
html.clear()
155160
}
@@ -175,7 +180,7 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
175180
classGenerator
176181
}).code
177182
const source = new ConcatSource(code)
178-
compilation.emitAsset(path.resolve(key, file), source)
183+
compilation.emitAsset(getEmitAssetPath(key, file), source)
179184
})
180185
js.clear()
181186
}
@@ -201,7 +206,7 @@ export const unplugin = createUnplugin((options: Options | undefined = {}, meta)
201206
runtimeSet
202207
})
203208
const source = new ConcatSource(newCss)
204-
compilation.emitAsset(path.resolve(key, file), source)
209+
compilation.emitAsset(getEmitAssetPath(key, file), source)
205210
})
206211
css.clear()
207212
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import path from 'path'
2+
3+
describe('path', () => {
4+
it('should be', () => {
5+
const context = 'C:\\github-workspace\\tailwindcss-mangle\\apps\\next-app\\.next\\'
6+
const target = path.resolve('C:\\github-workspace\\tailwindcss-mangle\\apps\\next-app\\.next\\server\\chunks', '../pages/_app.js')
7+
expect(path.relative(context, target)).toBe('')
8+
})
9+
})

0 commit comments

Comments
 (0)