Skip to content

Commit a407b6a

Browse files
committed
chore: release v1.2.0
1 parent e7392c7 commit a407b6a

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.0
2+
3+
- Support work with plugins that specify hook order.
4+
15
## 1.1.4
26

37
- Migrate to `tar-mini`

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vite-plugin-compression2",
33
"packageManager": "[email protected]",
4-
"version": "1.1.4",
4+
"version": "1.2.0",
55
"description": "a fast vite compression plugin",
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",

src/index.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,29 @@ function compression<T extends UserCompressionOptions, A extends Algorithm>(
205205
staticOutputs: new Set()
206206
}
207207

208-
return {
208+
let viteAnalyzerPlugin = null
209+
210+
const plugin = <Plugin>{
209211
name: VITE_COMPRESSION_PLUGIN,
210212
apply: 'build',
211213
enforce: 'post',
212214
api: pluginContext,
215+
options() {
216+
const { rollupVersion } = this.meta
217+
// issue #63
218+
// more and more plugin use are starting specify plugin order. So we should do a check for vite's version.
219+
const [major, minor] = rollupVersion.split('.')
220+
// rollup support object hook at 2.78.0
221+
if (+major < 2 && +minor < 78) {
222+
hijackGenerateBundle(viteAnalyzerPlugin, generateBundle)
223+
return
224+
}
225+
226+
plugin.generateBundle = {
227+
order: 'post',
228+
handler: generateBundle
229+
}
230+
},
213231
async configResolved(config) {
214232
// hijack vite's internal `vite:build-import-analysis` plugin.So we won't need process us chunks at closeBundle anymore.
215233
// issue #26
@@ -223,9 +241,8 @@ function compression<T extends UserCompressionOptions, A extends Algorithm>(
223241
await handleStaticFiles(config, async (file) => {
224242
statics.push(file)
225243
})
226-
const plugin = config.plugins.find(p => p.name === VITE_INTERNAL_ANALYSIS_PLUGIN)
227-
if (!plugin) throw new Error("[vite-plugin-compression] Can't be work in versions lower than vite at 2.0.0")
228-
hijackGenerateBundle(plugin, generateBundle)
244+
viteAnalyzerPlugin = config.plugins.find(p => p.name === VITE_INTERNAL_ANALYSIS_PLUGIN)
245+
if (!viteAnalyzerPlugin) throw new Error("[vite-plugin-compression] Can't be work in versions lower than vite at 2.0.0")
229246
},
230247
async closeBundle() {
231248
// parallel run
@@ -260,6 +277,8 @@ function compression<T extends UserCompressionOptions, A extends Algorithm>(
260277
await queue.wait().catch(e => e)
261278
}
262279
}
280+
281+
return plugin
263282
}
264283

265284
compression.getPluginAPI = (plugins: readonly Plugin[]): CompressionPluginAPI | undefined =>

0 commit comments

Comments
 (0)