代码拉取完成,页面将自动刷新
同步操作将从 DCloud/uni-app 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import { createRequire } from 'module'
import { fileURLToPath } from 'url'
import fs from 'fs'
import path from 'path'
import jscc from 'rollup-plugin-jscc'
import ts from 'rollup-plugin-typescript2'
import replace from '@rollup/plugin-replace'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { getBabelOutputPlugin } from '@rollup/plugin-babel'
if (!process.env.TARGET) {
throw new Error('TARGET package must be specified via --environment flag.')
}
const require = createRequire(import.meta.url)
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const packagesDir = path.resolve(__dirname, 'packages')
const packageDir = path.resolve(packagesDir, process.env.TARGET)
const resolve = (p) => path.resolve(packageDir, p)
const pkg = require(resolve(`package.json`))
// ensure TS checks only once for each build
let hasTSChecked = false
const configs = []
let buildOptions = require(resolve(`build.json`))
function normalizeOutput(file, output = {}) {
return Object.assign(
{
file,
format: file.includes('.cjs.') ? 'cjs' : 'es',
exports: 'auto',
interop: 'auto'
},
output
)
}
if (!Array.isArray(buildOptions)) {
buildOptions = [buildOptions]
}
buildOptions.forEach((buildOption) => {
Object.keys(buildOption.input).forEach((name) => {
const files = buildOption.input[name]
if (Array.isArray(files)) {
files.forEach((file) => {
configs.push(
createConfig(
name,
normalizeOutput(resolve(file), buildOption.output),
buildOption
)
)
})
} else {
configs.push(
createConfig(
name,
normalizeOutput(resolve(buildOption.input[name]), buildOption.output),
buildOption
)
)
}
})
})
export default configs
function resolveTsconfigJson() {
const tsconfigJsonPath = resolve('tsconfig.json')
if (
fs.existsSync(tsconfigJsonPath)
// &&
// require(tsconfigJsonPath).extends === '../../tsconfig.json'
) {
return tsconfigJsonPath
}
return path.resolve(__dirname, 'tsconfig.json')
}
function parseExternal(external) {
const parsed = external === false
? []
: Array.isArray(external)
? external
: [
'vue',
'@vue/shared',
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...(external || []),
]
return parsed.map((id) => {
if(typeof id === 'string') {
return id
}
return new RegExp(id.source, id.flags)
})
}
function createConfig(entryFile, output, buildOption) {
const shouldEmitDeclarations = process.env.TYPES != null && !hasTSChecked
const tsOptions = {
check: !process.env.TRANSPILE_ONLY &&
(!process.env.CI && process.env.NODE_ENV === 'production' && !hasTSChecked),
tsconfig: resolveTsconfigJson(),
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
tsconfigOverride: {
compilerOptions: {
sourceMap: output.sourcemap,
declaration: shouldEmitDeclarations,
declarationMap: false,
skipLibCheck: true,
...(buildOption.compilerOptions || {}),
},
exclude: ['**/__tests__', 'test-dts'],
},
useTsconfigDeclarationDir: true,
}
const tsPlugin = ts(tsOptions)
// we only need to check TS and generate declarations once for each build.
// it also seems to run into weird issues when checking multiple times
// during a single build.
hasTSChecked = true
const external = parseExternal(buildOption.external)
const isX = process.env.UNI_APP_X === 'true'
const plugins = [
createAliasPlugin(buildOption),
nodeResolve(),
commonjs(),
json({
// namedExports: false,
}),
tsPlugin,
createReplacePlugin(buildOption, output.format),
]
if (process.env.TARGET !== 'uni-push' && process.env.TARGET !== 'uni-stat') {
plugins.unshift(jscc({
values: {
// 该插件限制了不能以__开头
_NODE_JS_: 0,
_X_: isX ? 1 : 0,
},
exclude: ['**/node_modules/**']
}))
}
if (buildOption.babel) {
// TODO weex 使用了 buble 编译,暂时先通过 babel 编译一遍,避免 buble 编译失败
plugins.push(
getBabelOutputPlugin({
allowAllFormats: true,
sourceType: 'module',
presets: [['@babel/preset-env', { targets: ['iOS 10'] }]],
})
)
}
if (buildOption.replaceAfterBundled) {
const replacements = buildOption.replaceAfterBundled
plugins.push({
name: 'replace-after-bundled',
generateBundle(_options, bundles) {
Object.keys(bundles).forEach((name) => {
const bundle = bundles[name]
if (!bundle.code) {
return
}
Object.keys(replacements).forEach((replacement) => {
bundle.code = bundle.code.replace(
new RegExp(replacement, 'g'),
replacements[replacement]
)
})
})
},
})
}
return {
input: resolve(entryFile),
external,
plugins,
output,
onwarn: (msg, warn) => {
// if (!/Circular/.test(msg)) {
warn(msg)
// }
},
treeshake:
buildOption.treeshake === false
? false
: {
moduleSideEffects(id) {
if (id.endsWith('polyfill.ts')) {
console.log('[WARN]:sideEffects[' + id + ']')
return true
}
return false
},
},
}
}
function createAliasPlugin(buildOption) {
return alias(buildOption.alias || {})
}
function createReplacePlugin(buildOption, format) {
const replacements = {
__DEV__: `(process.env.NODE_ENV !== 'production')`,
__TEST__: false,
__NODE_JS__: format === 'cjs',
}
// if (process.env.TARGET === 'uni-h5') {
// replacements.global = format === 'cjs' ? 'global' : 'window'
// }
if (buildOption.replacements) {
Object.assign(replacements, buildOption.replacements)
}
Object.keys(replacements).forEach((key) => {
if (key in process.env) {
replacements[key] = process.env[key]
}
})
return replace({ delimiters: ['', ''], values: replacements, preventAssignment: true })
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。