提交 e18bd5bf 编写于 作者: Q qiang

Merge branch 'dev' of github.com:dcloudio/uni-app into dev

......@@ -162,7 +162,7 @@ uni.getSavedFileList({
|App|H5|微信小程序|支付宝小程序|百度小程序|头条小程序|QQ小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|√|x|√|√|√|√|√|
|√||√|√|√|√|√|
**OBJECT 参数说明:**
......
......@@ -33,6 +33,10 @@ const {
compileTemplate
} = require('./auto-components')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
module.exports = {
compile (source, options = {}) {
if ( // 启用摇树优化后,需要过滤内置组件
......@@ -192,10 +196,20 @@ at ${resourcePath}.vue:1`)
options.mp.filterModules.forEach(name => {
const filterModule = options.filterModules[name]
if (filterModule.type !== 'renderjs' && filterModule.attrs.lang !== 'renderjs') {
if (
filterModule.attrs &&
filterModule.attrs.src &&
filterModule.attrs.src.indexOf('@/') === 0
) {
const src = filterModule.attrs.src
filterModule.attrs.src = normalizePath(path.relative(
path.dirname(resourcePath), src.replace('@/', '')
))
}
filterTemplate.push(
options.mp.platform.createFilterTag(
options.filterTagName,
options.filterModules[name]
filterModule
)
)
}
......
......@@ -59,13 +59,21 @@ const sassLoader = {
}
if (sassLoaderVersion < 8) {
scssLoader.options.data = sassData
scssLoader.options.data = sassData
scssLoader.options.outputStyle = 'nested'
sassLoader.options.data = sassData
sassLoader.options.outputStyle = 'nested'
sassLoader.options.indentedSyntax = true
} else {
scssLoader.options.prependData = sassData
scssLoader.options.prependData = sassData
scssLoader.options.sassOptions = {
outputStyle: 'nested'
}
sassLoader.options.prependData = sassData
sassLoader.options.sassOptions = {
outputStyle: 'nested',
indentedSyntax: true
}
}
......
......@@ -137,15 +137,16 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
}
}
const babelLoaderRe = /^babel-loader|(\/|\\)babel-loader/
const cacheLoaderRe = /^cache-loader|(\/|\\)cache-loader/
return function (webpackConfig) {
// disable js cache-loader
const rawRules = webpackConfig.module.rules
for (let i = rawRules.length - 1; i >= 0; i--) {
const uses = rawRules[i].use
if (Array.isArray(uses)) {
if (uses.find(use => use.loader === 'babel-loader')) {
const index = uses.findIndex(use => use.loader === 'cache-loader')
if (uses.find(use => babelLoaderRe.test(use.loader))) {
const index = uses.findIndex(use => cacheLoaderRe.test(use.loader))
if (process.env.UNI_USING_CACHE) {
Object.assign(uses[index].options, api.genCacheConfig(
'babel-loader/' + process.env.UNI_PLATFORM,
......@@ -159,7 +160,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
// js preprocess
updateJsLoader(rawRules, 'foo.js', /^(.*[/\\])?babel-loader/, {
updateJsLoader(rawRules, 'foo.js', babelLoaderRe, {
loader: resolve('packages/webpack-preprocess-loader'),
options: jsPreprocessOptions
})
......
......@@ -23,7 +23,15 @@ export default function normalizeComponent (
// fixed by xxxxxx auto components
if (components) {
options.components = Object.assign(components, options.components || {})
if (!options.components) {
options.components = {}
}
var hasOwn = Object.prototype.hasOwnProperty
for (var name in components) {
if (hasOwn.call(components, name) && !hasOwn.call(options.components, name)) {
options.components[name] = components[name]
}
}
}
// fixed by xxxxxx renderjs
if (renderjs) {
......
const t = require('@babel/types')
const babelTemplate = require('@babel/template').default
const buildDynamicImport = babelTemplate(`var IMPORT_NAME = ()=>import(IMPORT_SOURCE)`, {
preserveComments: true,
plugins: [
'dynamicImport'
]
})
// const buildDynamicImport = babelTemplate(`var IMPORT_NAME = ()=>import(IMPORT_SOURCE)`, {
// preserveComments: true,
// plugins: [
// 'dynamicImport'
// ]
// })
// 已废弃,@vue/cli-plugin-babel@4 增加了 dynamic import 转换
// var test = ()=>import(/* webpackChunkName: "components/test" */'../../components/test')
function getDynamicImport (name, source, chunkName) {
const stringLiteral = t.stringLiteral(source)
const dynamicImportComment = {
type: 'CommentBlock',
value: `webpackChunkName: "${chunkName}"`
}
stringLiteral.leadingComments = [dynamicImportComment]
return buildDynamicImport({
// function getDynamicImport (name, source, chunkName) {
// const stringLiteral = t.stringLiteral(source)
// const dynamicImportComment = {
// type: 'CommentBlock',
// value: `webpackChunkName: "${chunkName}"`
// }
// stringLiteral.leadingComments = [dynamicImportComment]
// return buildDynamicImport({
// IMPORT_NAME: t.identifier(name),
// IMPORT_SOURCE: stringLiteral
// })
// }
// var test = function(resolve) {require.ensure([], () => resolve(require('../../components/test')),'components/test')}
const buildRequireEnsure = babelTemplate(
`var IMPORT_NAME = function(){require.ensure([],()=>resolve(require(IMPORT_SOURCE)),CHUNK_NAME)}`
)
function getRequireEnsure (name, source, chunkName) {
return buildRequireEnsure({
IMPORT_NAME: t.identifier(name),
IMPORT_SOURCE: stringLiteral
IMPORT_SOURCE: t.stringLiteral(source),
CHUNK_NAME: t.stringLiteral(chunkName)
})
}
......@@ -30,7 +43,7 @@ module.exports = function ({
const dynamicImport = state.opts.dynamicImports[path.node.source.value]
if (dynamicImport) {
path.insertBefore(
getDynamicImport(
getRequireEnsure(
path.node.specifiers[0].local.name,
dynamicImport.source,
dynamicImport.chunkName
......
......@@ -9,7 +9,6 @@ export default [
'getSavedFileList',
'getSavedFileInfo',
'removeSavedFileInfo',
'getFileInfo',
'onMemoryWarning',
'onGyroscopeChange',
'startGyroscope',
......
import {
urlToFile
} from 'uni-platform/helpers/file'
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
export function getFileInfo ({
filePath
} = {}, callbackId) {
// TODO 计算文件摘要
urlToFile(filePath).then((res) => {
invoke(callbackId, {
errMsg: 'getFileInfo:ok',
size: res.size
})
}).catch((err) => {
invoke(callbackId, {
errMsg: 'getFileInfo:fail 文件[' +
filePath +
'] getFileInfo 失败:' + err.message
})
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册