build: external packages (#3415)

This commit is contained in:
三咲智子 2021-09-15 08:28:23 +08:00 committed by GitHub
parent 5978ebdabd
commit a3f01b0f23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 56 deletions

View File

@ -1,52 +0,0 @@
/* eslint-disable */
import fs from 'fs'
import save from 'file-save'
import { resolve, basename } from 'path'
import { buildOutput } from './paths'
import babel from '@babel/core'
import type { FileResultCallback } from '@babel/core'
const localePath = resolve(__dirname, '../packages/locale/lang')
const fileList = fs.readdirSync(localePath)
const transform = function (
filename: string,
name: string,
cb: FileResultCallback
) {
babel.transformFile(
resolve(localePath, filename),
{
plugins: ['@babel/plugin-transform-modules-umd'],
moduleId: name,
},
cb
)
}
fileList
.filter(function (file) {
return /\.ts$/.test(file)
})
.forEach(function (file) {
const name = basename(file, '.ts')
transform(file, name, function (err, result) {
if (err) {
console.error(err)
} else {
const code = result!.code!
const transformedCode = code
.replace('define("', 'define("element/locale/')
.replace(
/global\.(\S*) = mod.exports/,
'global.ElementPlus.lang = global.ElementPlus.lang || {};\n global.ElementPlus.lang.$1 = mod.exports.default'
)
save(
resolve(buildOutput, 'element-plus/dist/locale', `${name}.js`)
).write(transformedCode)
}
})
})

View File

@ -18,12 +18,12 @@ export const getCpuCount = () => os.cpus().length
export const getPkgs = (): { name: string }[] => getPackagesSync()
export const getExternals = (options: { full: boolean }) => (id: string) => {
const packages: string[] = ['vue', '@vue']
const packages: string[] = ['vue']
if (!options.full) {
const compPkg = path.resolve(compRoot, './package.json')
const monoPackages = getPkgs().map((pkg) => pkg.name)
const depPackages = getDeps(compPkg)
packages.push(...monoPackages, ...depPackages)
packages.push('@vue', ...monoPackages, ...depPackages)
}
return [...new Set(packages)].some(

View File

@ -12,7 +12,6 @@
"bootstrap": "yarn --frozen-lockfile && npx lerna bootstrap && yarn gen:version",
"clean:lib": "rimraf lib && rimraf es && rimraf dist",
"build": "sh scripts/build.sh",
"build:locale-umd": "esno ./build/build-locale.ts",
"build:helper": "esno build/build-helper.ts",
"build:indices": "esno build/build-indices.ts",
"build:comps": "rimraf dist/components && esno build/components.ts",

View File

@ -22,7 +22,6 @@ yarn build:hooks
yarn build:directives
yarn build:tokens
yarn build:full-bundle
yarn build:locale-umd
rsync -a dist/entry/types/ dist/element-plus/es/
rsync -a dist/entry/types/ dist/element-plus/lib/