提交 a5a85e67 编写于 作者: fxy060608's avatar fxy060608

feat: add move plugin

上级 374a50fc
......@@ -39,6 +39,7 @@
"debug": "^4.3.3",
"estree-walker": "^2.0.2",
"express": "^4.17.1",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.0",
"hash-sum": "^2.0.0",
"jsonc-parser": "^3.0.0",
......
......@@ -16,6 +16,7 @@ import {
import { createConfig } from './config'
import { createConfigResolved } from './configResolved'
import { uniCopyPlugin } from './plugins/copy'
// import { uniMovePlugin } from './plugins/move'
import {
initExtraPlugins,
initPluginUniOptions,
......@@ -161,5 +162,21 @@ export default function uniPlugin(
)
}
// let addSourceMapPlugin = false
// if (addSourceMapPlugin) {
// plugins.push(
// uniMovePlugin({
// apply: 'build',
// enforce: 'post',
// cwd: process.env.UNI_OUTPUT_DIR,
// pattern: '**/*.js.map',
// dest: path.resolve(
// process.env.UNI_OUTPUT_DIR,
// '../.s/' + process.env.UNI_PLATFORM
// ),
// })
// )
// }
return plugins
}
import path from 'path'
import fs from 'fs-extra'
import glob from 'fast-glob'
import type { Plugin } from 'vite'
interface UniMovePluginOptions {
apply: Plugin['apply']
enforce: Plugin['enforce']
/**
* 原始根目录
*/
cwd: string
/**
* glob pattern 如:**\/*.js.mp)
*/
pattern: string
/**
* 目标目录
*/
dest: string
}
export function uniMovePlugin({
apply,
enforce,
cwd,
pattern,
dest,
}: UniMovePluginOptions): Plugin {
return {
name: 'uni:move',
apply,
enforce,
async writeBundle() {
await Promise.all(
glob
.sync(pattern, {
cwd,
})
.map((filename) => {
return fs.move(
path.resolve(cwd, filename),
path.resolve(dest, filename)
)
})
)
},
}
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册