feat: 编译前端, 并丢弃 webpack
This commit is contained in:
36
server/compiler/transform.ts
Normal file
36
server/compiler/transform.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import babel from '@babel/core'
|
||||
import fs from 'node:fs/promises'
|
||||
import io from './io.js'
|
||||
|
||||
async function compileJs(path: string) {
|
||||
const result = await babel.transformFileAsync(path, {
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env", {
|
||||
modules: false,
|
||||
},
|
||||
],
|
||||
"@babel/preset-react",
|
||||
"@babel/preset-typescript",
|
||||
],
|
||||
targets: {
|
||||
chrome: "53",
|
||||
android: "40",
|
||||
},
|
||||
sourceMaps: true,
|
||||
})
|
||||
await fs.writeFile(path, result.code + '\n' + `//@ sourceMappingURL=${io.getName(path)}.map`)
|
||||
await fs.writeFile(path + '.map', JSON.stringify(result.map))
|
||||
console.log(`编译: ${path}`)
|
||||
}
|
||||
|
||||
export default function(source: string, output: string) {
|
||||
io.copyDir(source, output)
|
||||
io.listFiles(output, {
|
||||
recursive: true,
|
||||
fullPath: true,
|
||||
}).forEach(function (v) {
|
||||
if (/\.(t|j)sx?$/.test(v))
|
||||
compileJs(v)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user