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

feat(cli): support match-media

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