mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-17 01:56:16 -08:00
update vue template
This commit is contained in:
1 parent
0c0bcecb9e
commit
4b55b97e9e
91 files changed
+228
-1701
No files matched your search
+51
-28
@@ -2,58 +2,81 @@ import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { Parcel } from '@parcel/core'
|
||||
import cpy from 'cpy'
|
||||
import { glob } from 'glob'
|
||||
|
||||
const basePath = 'packages/artplayer'
|
||||
const i18nSrcDir = path.join(basePath, 'src/i18n')
|
||||
const distDir = path.join(basePath, 'dist/i18n')
|
||||
const compiledPath = path.resolve('docs/compiled/i18n')
|
||||
|
||||
const entries = glob.sync('*.js', {
|
||||
cwd: i18nSrcDir,
|
||||
ignore: ['index.js', 'zh-cn.js'],
|
||||
}).map(f => path.join(i18nSrcDir, f));
|
||||
}).map(f => path.join(i18nSrcDir, f))
|
||||
|
||||
(async function build() {
|
||||
async function buildI18n() {
|
||||
if (fs.existsSync(distDir)) {
|
||||
fs.rmSync(distDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
fs.mkdirSync(distDir, { recursive: true })
|
||||
|
||||
const bundler = new Parcel({
|
||||
// --- 1. 构建 global(.js) 到临时目录 ---
|
||||
const distJs = path.join(distDir, 'cjs')
|
||||
const bundlerJs = new Parcel({
|
||||
entries,
|
||||
defaultConfig: '@parcel/config-default',
|
||||
mode: 'production',
|
||||
defaultTargetOptions: {
|
||||
distDir,
|
||||
distDir: distJs,
|
||||
outputFormat: 'global',
|
||||
sourceMaps: false,
|
||||
isLibrary: true,
|
||||
engines: {
|
||||
browsers: ['last 1 Chrome version'],
|
||||
},
|
||||
},
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
engines: { browsers: ['last 1 Chrome version'] },
|
||||
},
|
||||
env: { NODE_ENV: 'production' },
|
||||
})
|
||||
await bundlerJs.run()
|
||||
console.log('✅ Built i18n global (.js)')
|
||||
|
||||
try {
|
||||
const { bundleGraph, buildTime } = await bundler.run()
|
||||
const bundles = bundleGraph.getBundles()
|
||||
console.log(`✨ Built [i18n] ${bundles.length} bundles in ${buildTime}ms`)
|
||||
await cpy(distDir, compiledPath)
|
||||
}
|
||||
catch (err) {
|
||||
console.error('❌ Build i18n failed.')
|
||||
if (err?.diagnostics) {
|
||||
console.error(err.diagnostics)
|
||||
// --- 2. 构建 esmodule(.mjs) 到临时目录 ---
|
||||
const distMjs = path.join(distDir, 'esm')
|
||||
const bundlerMjs = new Parcel({
|
||||
entries,
|
||||
defaultConfig: '@parcel/config-default',
|
||||
mode: 'production',
|
||||
defaultTargetOptions: {
|
||||
distDir: distMjs,
|
||||
outputFormat: 'esmodule',
|
||||
sourceMaps: false,
|
||||
isLibrary: true,
|
||||
engines: { browsers: ['last 1 Chrome version'] },
|
||||
},
|
||||
env: { NODE_ENV: 'production' },
|
||||
})
|
||||
const { bundleGraph } = await bundlerMjs.run()
|
||||
const bundles = bundleGraph.getBundles()
|
||||
for (const bundle of bundles) {
|
||||
if (bundle.type === 'js') {
|
||||
const oldPath = bundle.filePath
|
||||
const newPath = oldPath.replace(/\.js$/, '.mjs')
|
||||
fs.renameSync(oldPath, newPath)
|
||||
}
|
||||
else {
|
||||
console.error(err)
|
||||
}
|
||||
process.exitCode = 1
|
||||
}
|
||||
})()
|
||||
console.log('✅ Built i18n esm (.mjs)')
|
||||
|
||||
// --- 3. 合并两个目录到 dist/i18n ---
|
||||
for (const f of fs.readdirSync(distJs)) {
|
||||
fs.renameSync(path.join(distJs, f), path.join(distDir, f))
|
||||
}
|
||||
for (const f of fs.readdirSync(distMjs)) {
|
||||
fs.renameSync(path.join(distMjs, f), path.join(distDir, f))
|
||||
}
|
||||
fs.rmSync(distJs, { recursive: true, force: true })
|
||||
fs.rmSync(distMjs, { recursive: true, force: true })
|
||||
|
||||
console.log('✨ Finished building i18n with both .js and .mjs')
|
||||
}
|
||||
|
||||
buildI18n().catch((err) => {
|
||||
console.error('❌ Build i18n failed', err)
|
||||
process.exitCode = 1
|
||||
})
|
||||
Reference in new issue
Block a user