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

feat(cli): wxs,filter,import-sjs

上级 624ff73a
......@@ -79,7 +79,8 @@ const PLATFORMS = {
exts: false,
vue: '@dcloudio/vue-cli-plugin-uni/packages/h5-vue',
compiler: false,
megalo: false,
megalo: false,
filterTag: 'wxs',
subPackages: false,
cssVars: {
'--status-bar-height': '0px'
......@@ -398,8 +399,20 @@ function devtoolModuleFilenameTemplate (info) {
) {
return `uni-app:///${filePath}`
}
}
module.exports = {
}
const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g
function normalizeNodeModules (str) {
str = str.replace(NODE_MODULES_REGEX, 'node-modules')
if (process.env.UNI_PLATFORM === 'mp-alipay') {
str = str.replace('node-modules/@', 'node-modules/npm-scope-')
}
return str
}
module.exports = {
normalizeNodeModules,
isInHBuilderX,
isInHBuilderXAlpha,
runByHBuilderX: isInHBuilderX || !!process.env.UNI_HBUILDERX_PLUGINS,
......
{
"name": "@dcloudio/uni-cli-shared",
"version": "0.2.989",
"version": "0.2.990",
"description": "uni-cli-shared",
"main": "lib/index.js",
"files": [
......
......@@ -100,15 +100,18 @@ at ${resourcePath}.vue:1`)
}
const filterTemplate = []
options.mp.filterModules.forEach(name => {
const filterTag = options.filterTagName
const filterModule = options.filterModules[name]
if (filterModule.content) {
filterTemplate.push(`<${filterTag} module="${name}">
${filterModule.content}
</${filterTag}>`)
}
filterTemplate.push(
options.mp.platform.createFilterTag(
options.filterTagName,
options.filterModules[name]
)
)
})
if (filterTemplate.length) {
template = filterTemplate.join('\n') + '\n' + template
}
if (
process.UNI_ENTRY[resourcePath] &&
process.env.UNI_PLATFORM !== 'app-plus' &&
......
......@@ -42,6 +42,11 @@ module.exports = {
'regionchange': 'onRegionChange'
}
},
createFilterTag (filterTag, {
attrs
}) {
return `<${filterTag} name="${attrs.module}" from="${attrs.src}"></${filterTag}>`
},
getEventType (eventType) {
return EVENTS[eventType] || eventType
},
......
......@@ -46,7 +46,7 @@ const tags = [
'textarea',
'video',
'view',
'web-view',
'web-view',
'editor'
]
......@@ -55,13 +55,26 @@ module.exports = {
refInFor: 'data-ref-in-for',
specialEvents: {},
/**
* TODO 暂时先简单判断是不是自定义组件,
* 如果要依赖真实导入的组件识别,需要 template-loader 与 script-loader 结合,
* 目前 template 在前,script 在后,要做的话,就需要把 wxml 的生成机制放到 plugin 中才可以拿到真实的组件列表
*/
* TODO 暂时先简单判断是不是自定义组件,
* 如果要依赖真实导入的组件识别,需要 template-loader 与 script-loader 结合,
* 目前 template 在前,script 在后,要做的话,就需要把 wxml 的生成机制放到 plugin 中才可以拿到真实的组件列表
*/
isComponent (tagName) {
return !tags.includes(tagName)
},
createFilterTag (filterTag, {
content,
attrs
}) {
content = content.trim()
if (content) {
return `<${filterTag} module="${attrs.module}">
${content}
</${filterTag}>`
} else if (attrs.src) {
return `<${filterTag} src="${attrs.src}" module="${attrs.module}"></${filterTag}>`
}
},
getEventType (eventType) {
return EVENTS[eventType] || eventType
},
......
{
"name": "@dcloudio/uni-template-compiler",
"version": "1.0.0-alpha-22120190814002",
"version": "0.9.182",
"description": "uni-template-compiler",
"main": "lib/index.js",
"files": [
......
......@@ -80,6 +80,11 @@ module.exports = {
before: [`<template><App :keepAliveInclude="keepAliveInclude"/></template>`]
}
}
}, {
resourceQuery: /blockType=wxs/,
use: [{
loader: resolve('packages/webpack-uni-filter-loader')
}]
}]
},
resolveLoader: {
......@@ -90,7 +95,7 @@ module.exports = {
plugins
}
},
chainWebpack (webpackConfig) {
chainWebpack (webpackConfig) {
webpackConfig.plugins.delete('copy')
if (!process.env.UNI_OPT_PREFETCH) {
......@@ -106,16 +111,22 @@ module.exports = {
.use('vue-loader')
.tap(options => Object.assign(options, {
compiler: getPlatformCompiler(),
compilerOptions: require('./compiler-options'),
cacheDirectory: false,
compilerOptions: require('./compiler-options'),
cacheDirectory: false,
cacheIdentifier: false
}))
.end()
.use('uniapp-custom-block-loader')
.loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader'))
.options({
compiler: getPlatformCompiler()
})
.end()
.use('uniapp-scoped')
.loader(resolve('packages/webpack-scoped-loader'))
.end()
.uses
.delete('cache-loader')
.delete('cache-loader')
if (process.env.NODE_ENV === 'production') {
const module = webpackConfig.module
......
......@@ -119,6 +119,12 @@ module.exports = {
use: [{
loader: '@dcloudio/webpack-uni-mp-loader/lib/template'
}]
}, {
resourceQuery: [/blockType=wxs/, /blockType=filter/, /blockType=import-sjs/],
use: [{
loader: require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-filter-loader')
}]
}]
},
plugins: [
......@@ -128,6 +134,13 @@ module.exports = {
}
},
chainWebpack (webpackConfig) {
if (process.env.UNI_PLATFORM === 'mp-baidu') {
webpackConfig.module
.rule('js')
.exclude
.add(/\.filter\.js$/)
}
// disable vue cache-loader
webpackConfig.module
.rule('vue')
......
{
"name": "@dcloudio/vue-cli-plugin-uni",
"version": "0.9.525",
"version": "0.9.527",
"description": "uni-app plugin for vue-cli 3",
"main": "index.js",
"scripts": {
......
......@@ -8,15 +8,13 @@ const {
})) // 确保使用的与 vue-loader 一致
const {
getPlatformFilterTag
getPlatformFilterTag,
normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform')
const FILTER_TAG = getPlatformFilterTag()
module.exports = function(source) {
if (!FILTER_TAG) {
return source
}
const loaderContext = this
......@@ -40,23 +38,31 @@ module.exports = function(source) {
needMap: sourceMap
})
if (!descriptor.template) {
if (!descriptor.template || !FILTER_TAG) {
// delete customBlocks
descriptor.customBlocks.length = 0
return source
}
const modules = Object.create(null)
descriptor.customBlocks.filter(block => {
descriptor.customBlocks = descriptor.customBlocks.filter(block => {
if (block.type === FILTER_TAG && block.attrs.module) {
modules[block.attrs.module] = block
return true
}
})
if (Object.keys(modules)) {
descriptor.template.attrs['filter-modules'] = JSON.stringify(modules)
const filterModules = JSON.parse(JSON.stringify(modules))
Object.keys(filterModules).forEach(name => {
const filterModule = filterModules[name]
if (filterModule.attrs.src) {
filterModule.attrs.src = normalizeNodeModules(filterModule.attrs.src)
}
})
descriptor.template.attrs['filter-modules'] = JSON.stringify(filterModules)
}
// delete customBlocks
descriptor.customBlocks.length = 0
return source
}
const path = require('path')
const loaderUtils = require('loader-utils')
const {
normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform')
module.exports = function(source, map) {
const params = loaderUtils.parseQuery(this.resourceQuery)
if (process.env.UNI_PLATFORM === 'h5') { // h5
this.callback(
null,
`export default function (Component) {
(Component.options.wxs||(Component.options.wxs={}))['${params.module}'] = (function(module){
${source.trim()}
return module.exports
})({exports:{}});
}`,
map
)
} else { // mp
if (params.issuerPath) {
const resourcePath = normalizeNodeModules(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
this.emitFile(resourcePath, source)
}
this.callback(null, `export default {}`, map)
}
}
......@@ -3,8 +3,10 @@ const {
getPlatformExts,
getPlatformTarget
} = require('@dcloudio/uni-cli-shared')
const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g
const {
normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform')
const templates = {}
const compilerOptions = {}
......@@ -29,14 +31,6 @@ function resolve (source) {
})
}
function normalizeNodeModules (str) {
str = str.replace(NODE_MODULES_REGEX, 'node-modules')
if (process.env.UNI_PLATFORM === 'mp-alipay') {
str = str.replace('node-modules/@', 'node-modules/npm-scope-')
}
return str
}
function restoreNodeModules (str) {
if (process.env.UNI_PLATFORM === 'mp-alipay') {
str = str.replace('node-modules/npm-scope-', 'node-modules/@')
......
{
"name": "@dcloudio/webpack-uni-mp-loader",
"version": "1.0.0-alpha-22120190814002",
"version": "0.3.644",
"description": "webpack-uni-mp-loader",
"main": "index.js",
"files": [
......
{
"name": "@dcloudio/webpack-uni-pages-loader",
"version": "0.2.873",
"version": "0.2.874",
"description": "uni-app pages.json loader",
"main": "lib/index.js",
"files": [
......@@ -16,7 +16,7 @@
"strip-json-comments": "^2.0.1"
},
"uni-app": {
"compilerVersion": "2.2.1"
"compilerVersion": "2.2.3"
},
"gitHead": "08ea04b669e93f0db3acb2dfa38138298edd5789"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册