提交 6e2e7815 编写于 作者: fxy060608's avatar fxy060608

feat(cli): support match-media

上级 03cc15dd
......@@ -111,7 +111,7 @@ function isNVuePage (page, root = '') {
}
function isValidPage (page, root = '') {
if (typeof page === 'string' || !page.path) { // 不合法的配置
if (typeof page === 'string' || !page.path) { // 不合法的配置
console.warn('pages.json 页面配置错误, 已被忽略, 查看文档: https://uniapp.dcloud.io/collocation/pages?id=pages')
return false
}
......@@ -392,14 +392,13 @@ function initAutoImportComponents (easycom = {}) {
}
// 目前仅 mp-weixin 内置支持 page-meta 等组件
if (process.env.UNI_PLATFORM !== 'mp-weixin') {
if (!usingAutoImportComponents['^page-meta$']) {
usingAutoImportComponents['^page-meta$'] =
'@dcloudio/uni-cli-shared/components/page-meta.vue'
}
if (!usingAutoImportComponents['^navigation-bar$']) {
usingAutoImportComponents['^navigation-bar$'] =
'@dcloudio/uni-cli-shared/components/navigation-bar.vue'
}
BUILT_IN_COMPONENTS.forEach(name => {
const easycomName = `^${name}$`
if (!usingAutoImportComponents[easycomName]) {
usingAutoImportComponents[easycomName] =
'@dcloudio/uni-cli-shared/components/' + name + '.vue'
}
})
}
const newUsingAutoImportComponentsJson = JSON.stringify(usingAutoImportComponents)
......@@ -463,7 +462,20 @@ function parseUsingAutoImportComponents (usingAutoImportComponents) {
}
return autoImportComponents
}
const BUILT_IN_COMPONENTS = ['page-meta', 'navigation-bar', 'match-media']
function isBuiltInComponent (name) {
return BUILT_IN_COMPONENTS.includes(name)
}
function isBuiltInComponentPath (modulePath) {
return !!BUILT_IN_COMPONENTS.find(name => modulePath.includes(name))
}
module.exports = {
isBuiltInComponent,
isBuiltInComponentPath,
getMainEntry,
getNVueMainEntry,
parsePages,
......
......@@ -181,6 +181,10 @@ function hasOwn (obj, key) {
const tags = require('@dcloudio/uni-cli-shared/lib/tags')
const {
isBuiltInComponent
} = require('@dcloudio/uni-cli-shared/lib/pages')
const {
getTagName
} = require('./h5')
......@@ -196,7 +200,7 @@ function isComponent (tagName) {
}
// mp-weixin 底层支持 page-meta,navigation-bar
if (process.env.UNI_PLATFORM === 'mp-weixin') {
if (tagName === 'page-meta' || tagName === 'navigation-bar') {
if (isBuiltInComponent(tagName)) {
return false
}
}
......@@ -219,7 +223,11 @@ function makeMap (str, expectsLowerCase) {
* @param {*} node
*/
function isSimpleObjectExpression (node) {
return t.isObjectExpression(node) && !node.properties.find(({ key, value }) => !t.isIdentifier(key) || !(t.isIdentifier(value) || t.isStringLiteral(value) || t.isBooleanLiteral(value) || t.isNumericLiteral(value) || t.isNullLiteral(value)))
return t.isObjectExpression(node) && !node.properties.find(({
key,
value
}) => !t.isIdentifier(key) || !(t.isIdentifier(value) || t.isStringLiteral(value) || t.isBooleanLiteral(value) ||
t.isNumericLiteral(value) || t.isNullLiteral(value)))
}
module.exports = {
......@@ -253,4 +261,4 @@ module.exports = {
processMemberExpression,
getForIndexIdentifier,
isSimpleObjectExpression
}
}
......@@ -10,6 +10,10 @@ const {
getJsonFile
} = require('@dcloudio/uni-cli-shared/lib/cache')
const {
isBuiltInComponentPath
} = require('@dcloudio/uni-cli-shared/lib/pages')
const {
restoreNodeModules
} = require('../shared')
......@@ -88,10 +92,7 @@ module.exports = function generateComponent (compilation) {
if (
/^win/.test(process.platform) &&
modulePath.includes('@dcloudio') &&
(
modulePath.includes('page-meta') ||
modulePath.includes('navigation-bar')
)
isBuiltInComponentPath(modulePath)
) {
resource = normalizePath(path.resolve(process.env.UNI_CLI_CONTEXT, modulePath))
}
......@@ -233,4 +234,4 @@ function removeUnusedComponent (name) {
fs.renameSync(path.join(process.env.UNI_OUTPUT_DIR, name + '.json'), path.join(process.env.UNI_OUTPUT_DIR, name +
'.bak.json'))
} catch (e) {}
}
}
......@@ -12,7 +12,11 @@ const {
const {
getBabelParserOptions
} = require('@dcloudio/uni-cli-shared/lib/platform')
} = require('@dcloudio/uni-cli-shared/lib/platform')
const {
isBuiltInComponentPath
} = require('@dcloudio/uni-cli-shared/lib/pages')
const {
updateUsingComponents
......@@ -61,11 +65,8 @@ module.exports = function (content, map) {
if ( // windows 上 page-meta, navigation-bar 可能在不同盘上
/^win/.test(process.platform) &&
path.isAbsolute(resourcePath) &&
(
resourcePath.indexOf('page-meta') !== -1 ||
resourcePath.indexOf('navigation-bar') !== -1
)
path.isAbsolute(resourcePath) &&
isBuiltInComponentPath(resourcePath)
) {
resourcePath = normalizePath(path.relative(process.env.UNI_CLI_CONTEXT, resourcePath))
}
......
......@@ -19,6 +19,10 @@ const {
updateUsingGlobalComponents
} = require('@dcloudio/uni-cli-shared/lib/cache')
const {
isBuiltInComponentPath
} = require('@dcloudio/uni-cli-shared/lib/pages')
const {
getPlatformFilterTag
} = require('@dcloudio/uni-cli-shared/lib/platform')
......@@ -49,10 +53,7 @@ module.exports = function (content, map) {
if ( // windows 上 page-meta, navigation-bar 可能在不同盘上
/^win/.test(process.platform) &&
path.isAbsolute(resourcePath) &&
(
resourcePath.indexOf('page-meta') !== -1 ||
resourcePath.indexOf('navigation-bar') !== -1
)
isBuiltInComponentPath(resourcePath)
) {
resourcePath = normalizePath(path.relative(process.env.UNI_CLI_CONTEXT, resourcePath))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册