-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
hook
option to control when plugin is ran (#133)
- Loading branch information
1 parent
c3a1474
commit b9c09bd
Showing
5 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'vite-plugin-static-copy': minor | ||
--- | ||
|
||
Allows user to optionally configure when the plugin is ran by passing in a Rollup hook name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { defineConfig, normalizePath } from 'vite' | ||
import { viteStaticCopy } from 'vite-plugin-static-copy' | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
import url from 'node:url' | ||
|
||
const _dirname = path.dirname(url.fileURLToPath(import.meta.url)) | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
viteStaticCopy({ | ||
targets: [ | ||
{ | ||
src: 'foo.txt', | ||
dest: 'hook1' | ||
} | ||
], | ||
hook: 'generateBundle' | ||
}), | ||
testHookPlugin() | ||
] | ||
}) | ||
|
||
function testHookPlugin() { | ||
return { | ||
name: 'test-hook-plugin', | ||
async writeBundle() { | ||
const filePath = normalizePath( | ||
path.resolve(_dirname, 'dist', 'hook1', 'foo.txt') | ||
) | ||
await fs.access(filePath) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters