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

fix(app): sourcemap

上级 5c8e32ab
import fs from 'fs'
import path from 'path'
import debug from 'debug'
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
......@@ -9,6 +10,7 @@ import legacyPlugin from '@vitejs/plugin-legacy'
import {
CopyOptions,
emptyDir,
initModuleAlias,
initPreContext,
parsePagesJsonOnce,
......@@ -67,6 +69,8 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
export { runDev, runBuild } from './cli/action'
let isFirst = true
export default function uniPlugin(
rawOptions: VitePluginUniOptions = {}
): Plugin[] {
......@@ -181,13 +185,23 @@ export default function uniPlugin(
}
if (process.env.SOURCEMAP === 'true') {
// 清空之前的 sourcemap 目录
const sourceMapPath = resolveSourceMapPath()
if (isFirst) {
// 避免重复清空
isFirst = false
if (fs.existsSync(sourceMapPath)) {
emptyDir(sourceMapPath)
}
}
plugins.push(
uniMovePlugin({
apply: 'build',
enforce: 'post',
cwd: process.env.UNI_OUTPUT_DIR,
pattern: '**/*.js.map',
dest: resolveSourceMapPath(),
dest: sourceMapPath,
})
)
}
......
......@@ -38,7 +38,6 @@ export function uniMovePlugin({
cwd,
})
.map((filename) => {
fs.removeSync(dest)
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.
先完成此消息的编辑!
想要评论请 注册