提交 f5541b8f 编写于 作者: Q qiang

style: CRLF -> LF

上级 a2ebf0c4
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { const {
isInHBuilderX, isInHBuilderX,
isInHBuilderXAlpha, isInHBuilderXAlpha,
normalizeNodeModules normalizeNodeModules
} = require('./util') } = require('./util')
const { const {
SCSS, SCSS,
SASS SASS
} = require('./scss') } = require('./scss')
function getShadowCss () { function getShadowCss () {
let tagName = 'page' let tagName = 'page'
if (process.env.UNI_PLATFORM === 'h5') { if (process.env.UNI_PLATFORM === 'h5') {
tagName = 'body' tagName = 'body'
} }
const cdn = getShadowCdn() const cdn = getShadowCdn()
return `${tagName}::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}` return `${tagName}::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}`
} }
const cdns = { const cdns = {
'mp-weixin': 1, 'mp-weixin': 1,
'mp-alipay': 2, 'mp-alipay': 2,
'mp-baidu': 3, 'mp-baidu': 3,
'mp-toutiao': 4, 'mp-toutiao': 4,
'mp-qq': 5, 'mp-qq': 5,
'mp-360': 7, 'mp-360': 7,
'mp-dingtalk': 8, 'mp-dingtalk': 8,
'mp-kuaishou': 9, 'mp-kuaishou': 9,
'mp-lark': 10, 'mp-lark': 10,
'mp-jd': 11, 'mp-jd': 11,
'mp-xhs': 12, 'mp-xhs': 12,
'quickapp-webview-huawei': 200, 'quickapp-webview-huawei': 200,
'quickapp-webview-union': 201 'quickapp-webview-union': 201
} }
function getShadowCdn () { function getShadowCdn () {
const index = cdns[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || '' const index = cdns[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || ''
return `https://cdn${index}.dcloud.net.cn` return `https://cdn${index}.dcloud.net.cn`
} }
// 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在 // 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5' process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
const uniPluginOptions = global.uniPlugin.options || {} const uniPluginOptions = global.uniPlugin.options || {}
const { const {
vueContext: preprocessContext, vueContext: preprocessContext,
nvueContext: nvuePreprocessContext nvueContext: nvuePreprocessContext
} = global.uniPlugin.preprocess } = global.uniPlugin.preprocess
// TODO 暂时保留原有导出,减少影响,后续再整理一下 // TODO 暂时保留原有导出,减少影响,后续再整理一下
module.exports = { module.exports = {
normalizeNodeModules, normalizeNodeModules,
isInHBuilderX, isInHBuilderX,
isInHBuilderXAlpha, isInHBuilderXAlpha,
runByHBuilderX: isInHBuilderX || fs.existsSync(path.resolve(process.env.UNI_HBUILDERX_PLUGINS || '', runByHBuilderX: isInHBuilderX || fs.existsSync(path.resolve(process.env.UNI_HBUILDERX_PLUGINS || '',
'weapp-tools')), 'weapp-tools')),
getFlexDirection (json) { getFlexDirection (json) {
let flexDir = 'column' let flexDir = 'column'
if (json && json.nvue && json.nvue['flex-direction']) { if (json && json.nvue && json.nvue['flex-direction']) {
flexDir = json.nvue['flex-direction'] flexDir = json.nvue['flex-direction']
const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse'] const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse']
if (flexDirs.indexOf(flexDir) === -1) { if (flexDirs.indexOf(flexDir) === -1) {
flexDir = 'column' flexDir = 'column'
} }
} }
return flexDir return flexDir
}, },
jsPreprocessOptions: { jsPreprocessOptions: {
type: 'js', type: 'js',
context: preprocessContext context: preprocessContext
}, },
cssPreprocessOptions: { cssPreprocessOptions: {
type: 'css', type: 'css',
context: preprocessContext context: preprocessContext
}, },
htmlPreprocessOptions: { htmlPreprocessOptions: {
type: 'html', type: 'html',
context: preprocessContext context: preprocessContext
}, },
nvueCssPreprocessOptions: { nvueCssPreprocessOptions: {
type: 'css', type: 'css',
context: nvuePreprocessContext context: nvuePreprocessContext
}, },
nvueJsPreprocessOptions: { nvueJsPreprocessOptions: {
type: 'js', type: 'js',
context: nvuePreprocessContext context: nvuePreprocessContext
}, },
nvueHtmlPreprocessOptions: { nvueHtmlPreprocessOptions: {
type: 'html', type: 'html',
context: nvuePreprocessContext context: nvuePreprocessContext
}, },
isSupportSubPackages () { isSupportSubPackages () {
return !!uniPluginOptions.subPackages return !!uniPluginOptions.subPackages
}, },
getPlatforms () { getPlatforms () {
return global.uniPlugin.platforms return global.uniPlugin.platforms
}, },
getPlatformGlobal () { // 目前仅mp-alipay有用 getPlatformGlobal () { // 目前仅mp-alipay有用
return uniPluginOptions.global return uniPluginOptions.global
}, },
getPlatformExts () { // 小程序扩展名 getPlatformExts () { // 小程序扩展名
return uniPluginOptions.extnames return uniPluginOptions.extnames
}, },
getPlatformProject () { // 开发工具项目配置名 getPlatformProject () { // 开发工具项目配置名
return uniPluginOptions.project return uniPluginOptions.project
}, },
getPlatformFilterTag () { getPlatformFilterTag () {
return uniPluginOptions.filterTag return uniPluginOptions.filterTag
}, },
getMPRuntimePath () { getMPRuntimePath () {
if (process.env.UNI_USING_VUE3) { if (process.env.UNI_USING_VUE3) {
try { try {
return require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM + '/dist/uni.mp.esm.js') return require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM + '/dist/uni.mp.esm.js')
} catch (error) { } catch (error) {
throw new Error('Vue3 项目暂不支持当前小程序') throw new Error('Vue3 项目暂不支持当前小程序')
} }
} }
return require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM) return require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM)
}, },
getPlatformVue (vueOptions) { getPlatformVue (vueOptions) {
if (uniPluginOptions.vue) { if (uniPluginOptions.vue) {
return uniPluginOptions.vue return uniPluginOptions.vue
} }
if (process.env.UNI_USING_VUE3) { if (process.env.UNI_USING_VUE3) {
return '@dcloudio/uni-mp-vue' return '@dcloudio/uni-mp-vue'
} }
return '@dcloudio/vue-cli-plugin-uni/packages/mp-vue' return '@dcloudio/vue-cli-plugin-uni/packages/mp-vue'
}, },
getPlatformCssVars () { getPlatformCssVars () {
return uniPluginOptions.cssVars || {} return uniPluginOptions.cssVars || {}
}, },
getPlatformCssnano () { getPlatformCssnano () {
return { return {
calc: false, calc: false,
orderedValues: false, orderedValues: false,
mergeLonghand: false, mergeLonghand: false,
mergeRules: false, mergeRules: false,
cssDeclarationSorter: false, cssDeclarationSorter: false,
uniqueSelectors: false, // 标签排序影响头条小程序 uniqueSelectors: false, // 标签排序影响头条小程序
minifySelectors: false, // 标签排序影响头条小程序 minifySelectors: false, // 标签排序影响头条小程序
discardComments: false, discardComments: false,
discardDuplicates: false // 条件编译会导致重复 discardDuplicates: false // 条件编译会导致重复
} }
}, },
getShadowCss, getShadowCss,
getShadowTemplate (colorType = 'grey') { getShadowTemplate (colorType = 'grey') {
let tagName = 'cover-image' let tagName = 'cover-image'
if (process.env.UNI_PLATFORM === 'mp-toutiao' || process.env.UNI_PLATFORM === 'mp-lark') { if (process.env.UNI_PLATFORM === 'mp-toutiao' || process.env.UNI_PLATFORM === 'mp-lark') {
tagName = 'image' tagName = 'image'
} }
return `<${tagName} src="${getShadowCdn()}/img/shadow-${colorType}.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>` return `<${tagName} src="${getShadowCdn()}/img/shadow-${colorType}.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
}, },
getPlatformScss () { getPlatformScss () {
return SCSS return SCSS
}, },
getPlatformSass () { getPlatformSass () {
return SASS return SASS
}, },
getPlatformStat () { getPlatformStat () {
if (!process.env.UNI_USING_STAT) { if (!process.env.UNI_USING_STAT) {
return '' return ''
} }
return process.env.UNI_USING_STAT === '2' ? 'import \'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js\';' return process.env.UNI_USING_STAT === '2' ? 'import \'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js\';'
: 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';' : 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
}, },
getBabelParserOptions () { getBabelParserOptions () {
return { return {
sourceType: 'module', sourceType: 'module',
plugins: [ plugins: [
['pipelineOperator', { ['pipelineOperator', {
proposal: 'minimal' proposal: 'minimal'
}], }],
'doExpressions', 'doExpressions',
'optionalChaining', 'optionalChaining',
'typescript', 'typescript',
['decorators', { ['decorators', {
decoratorsBeforeExport: true decoratorsBeforeExport: true
}], }],
'classProperties' 'classProperties'
] ]
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册