Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

插件执行的顺序 #17

Open
RayPS opened this issue Mar 12, 2022 · 2 comments
Open

插件执行的顺序 #17

RayPS opened this issue Mar 12, 2022 · 2 comments

Comments

@RayPS
Copy link

RayPS commented Mar 12, 2022

我想在 viteCompression 之后增加一个自定义的 Vite 插件,但是我增加的插件无法保证在 viteCompression 后面执行,总是先于它执行,为什么呢?

vite.config.ts:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteSingleFile } from 'vite-plugin-singlefile'
import viteCompression from 'vite-plugin-compression'
import vitePROGMEM from './vite-plugin-progmem' // <-- 自定义插件

export default defineConfig({
	plugins: [
		vue(),
		viteSingleFile(),
		viteCompression(),
		vitePROGMEM({
			source: './dist/index.html.gz',
			destination: './dist/index.h'
		})
	],
	//...
})

vite-plugin-progmem:

import { Plugin } from "vite"
import * as fs from 'fs'

interface vitePluginPROGMEMOptions {
    /**
     * Source of the .html.gz file
     */
     source: string;
     /**
      * Destination of the .h file
      */
     destination: string;
}

export default function vitePROGMEM(options: vitePluginPROGMEMOptions): Plugin {
  return {
    name: "vite:progmem",
    apply: 'build',
    async closeBundle() {
      console.log(options)
      console.log('source: ' + fs.existsSync(options.source));
      console.log('destination: ' + fs.existsSync(options.destination));
      // .gz 文件不存在
    }
  }
}
@xlanghejianfeng
Copy link

同样的问题,难道不能以插件的形式,只能用success方法来回调了?

@hn-failte
Copy link

这个问题我也遇到了,原因是源码里面的closeBundle函数根本就不能是一个async函数 里面的await全都没用、我改成node的同步函数就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants