mirror of
https://github.com/xiaoyiweb/YiAi.git
synced 2025-11-13 20:53:47 +08:00
初始化
This commit is contained in:
49
admin/vite/plugins/spritesmith.ts
Normal file
49
admin/vite/plugins/spritesmith.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import fs from 'fs'
|
||||
import spritesmith from 'vite-plugin-spritesmith'
|
||||
|
||||
export default function createSpritesmith(isBuild) {
|
||||
const spriteDirnames: string[] = []
|
||||
fs.readdirSync('src/assets/sprites').forEach((dirname) => {
|
||||
if (fs.statSync(`src/assets/sprites/${dirname}`).isDirectory()) {
|
||||
spriteDirnames.push(dirname)
|
||||
}
|
||||
})
|
||||
const plugin: any[] = []
|
||||
spriteDirnames.forEach((item) => {
|
||||
plugin.push(
|
||||
spritesmith({
|
||||
watch: !isBuild,
|
||||
src: {
|
||||
cwd: `./src/assets/sprites/${item}`,
|
||||
glob: '*.png',
|
||||
},
|
||||
target: {
|
||||
image: `./src/assets/sprites/${item}.png`,
|
||||
css: [
|
||||
[
|
||||
`./src/assets/sprites/_${item}.scss`,
|
||||
{
|
||||
format: 'handlebars_based_template',
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
apiOptions: {
|
||||
cssImageRef: `@/assets/sprites/${item}.png`,
|
||||
spritesheet_info: {
|
||||
name: item,
|
||||
format: 'handlebars_based_template',
|
||||
},
|
||||
},
|
||||
customTemplates: {
|
||||
handlebars_based_template: './scss.template.hbs',
|
||||
},
|
||||
spritesmithOptions: {
|
||||
algorithm: 'binary-tree',
|
||||
padding: 10,
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
return plugin
|
||||
}
|
||||
Reference in New Issue
Block a user