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

refactor(cli): source-map

上级 82f0936c
src/core/helpers/html-parser.js src/core/helpers/html-parser.js
src/platforms/app-plus-nvue/runtime src/platforms/app-plus-nvue/runtime
build/rollup-plugin-require-context build/rollup-plugin-require-context
packages/*/packages packages/*/packages/uni-app-plus
packages/*/packages/uni-app-plus-nvue
packages/*/packages/uni-app-plus-nvue-v8
packages/*/packages/weex-styler
packages/*/packages/weex-template-compiler
packages/*/packages/@intervolga
packages/*/packages/@megalo
packages/*/packages/@vue
packages/*/packages/app-vue-style-loader
packages/*/packages/h5-vue
packages/*/packages/h5-vue-router
packages/*/packages/h5-vue-style-loader
packages/*/packages/megalo
packages/*/packages/mp-vue
packages/*/packages/mpvue
packages/*/packages/mpvue-page-factory
packages/*/packages/mpvue-template-compiler
packages/*/packages/postcss-normalize-whitespace
packages/*/packages/uni-cloud
packages/*/packages/vue-loader
packages/*/packages/vue-template-compiler
packages/*/packages/webpack-preprocess-loader/preprocess
packages/*/template/**/* packages/*/template/**/*
packages/uni-h5/src packages/uni-h5/src
packages/uni-stat packages/uni-stat
......
...@@ -47,10 +47,5 @@ module.exports = { ...@@ -47,10 +47,5 @@ module.exports = {
}, },
'hybrid/html' 'hybrid/html'
] ]
},
configureWebpack() {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'cheap-module-eval-source-map'
}
} }
} }
...@@ -5187,8 +5187,7 @@ var serviceContext = (function () { ...@@ -5187,8 +5187,7 @@ var serviceContext = (function () {
// tabBar是否遮挡内容区域 // tabBar是否遮挡内容区域
get cover () { get cover () {
const array = ['extralight', 'light', 'dark']; const array = ['extralight', 'light', 'dark'];
// 设置背景颜色会失效 return isIOS$1 && array.indexOf(config.blurEffect) >= 0
return isIOS$1 && array.indexOf(config.blurEffect) >= 0 && !config.backgroundColor
}, },
setStyle ({ mask }) { setStyle ({ mask }) {
tabBar.setMask({ tabBar.setMask({
...@@ -8246,7 +8245,7 @@ var serviceContext = (function () { ...@@ -8246,7 +8245,7 @@ var serviceContext = (function () {
} }
} }
function showWebview (webview, animationType, animationDuration, showCallback, delay) { function showWebview (webview, animationType, animationDuration, showCallback, delay) {
if (typeof delay === 'undefined') { if (typeof delay === 'undefined') {
delay = webview.nvue ? 0 : 100; delay = webview.nvue ? 0 : 100;
} }
...@@ -8260,16 +8259,36 @@ var serviceContext = (function () { ...@@ -8260,16 +8259,36 @@ var serviceContext = (function () {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`[show][${Date.now()}]`, delay); console.log(`[show][${Date.now()}]`, delay);
} }
const duration = animationDuration || ANI_DURATION;
setTimeout(() => { setTimeout(() => {
const execShowCallback = function () {
if (execShowCallback._called) {
if (process.env.NODE_ENV !== 'production') {
console.log('execShowCallback.prevent');
}
return
}
execShowCallback._called = true;
showCallback && showCallback();
navigateFinish();
};
const timer = setTimeout(() => {
if (process.env.NODE_ENV !== 'production') {
console.log(`[show.callback.timer][${Date.now()}]`);
}
execShowCallback();
}, duration + 150);
webview.show( webview.show(
animationType || ANI_SHOW, animationType || ANI_SHOW,
animationDuration || ANI_DURATION, duration,
() => { () => {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`[show.callback][${Date.now()}]`); console.log(`[show.callback][${Date.now()}]`);
} }
showCallback && showCallback(); if (!execShowCallback._called) {
navigateFinish(); clearTimeout(timer);
}
execShowCallback();
} }
); );
}, delay); }, delay);
...@@ -8294,11 +8313,11 @@ var serviceContext = (function () { ...@@ -8294,11 +8313,11 @@ var serviceContext = (function () {
mpType: 'page', mpType: 'page',
pageId, pageId,
pagePath, pagePath,
pageQuery, pageQuery,
pageInstance pageInstance
}); });
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`new ${pagePath}`, Date.now() - startTime); console.log(`new ${pagePath}[${pageId}]:time(${Date.now() - startTime})`);
} }
return pageVm return pageVm
} }
...@@ -8383,7 +8402,7 @@ var serviceContext = (function () { ...@@ -8383,7 +8402,7 @@ var serviceContext = (function () {
} }
pages.splice(index, 1); pages.splice(index, 1);
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log('[uni-app] removePage', path, webview.id); console.log('[uni-app] removePage(' + path + ')[' + webview.id + ']');
} }
} }
}, },
......
...@@ -40,20 +40,5 @@ module.exports = { ...@@ -40,20 +40,5 @@ module.exports = {
copyOptions.push(path.resolve(__dirname, '../template/v3')) copyOptions.push(path.resolve(__dirname, '../template/v3'))
} }
return copyOptions return copyOptions
},
configureWebpack (webpackConfig, vueOptions) {
let devtool = false
if (process.env.NODE_ENV !== 'production') {
if (process.env.UNI_USING_V3) {
if (vueOptions.pluginOptions['uni-app-plus'].service) {
devtool = 'eval-source-map'
}
} else {
devtool = 'eval-source-map'
}
}
return {
devtool
}
} }
} }
const path = require('path')
const webpack = require('webpack')
const {
normalizePath,
isInHBuilderX
} = require('@dcloudio/uni-cli-shared/lib/util')
const isWin = /^win/.test(process.platform)
function genTranspileDepRegex (depPath) {
return new RegExp(isWin
? depPath.replace(/\\/g, '\\\\') // double escape for windows style path
: depPath)
}
let sourceRoot = false
function getSourceRoot () {
if (!sourceRoot) {
if (isInHBuilderX) {
sourceRoot = normalizePath(process.env.UNI_INPUT_DIR)
} else {
sourceRoot = normalizePath(process.env.UNI_CLI_CONTEXT)
}
}
return sourceRoot
}
function moduleFilenameTemplate (info) {
if (!info.allLoaders && info.resourcePath) {
const filepath = normalizePath(path.relative(getSourceRoot(), info.absoluteResourcePath))
if (filepath.indexOf('../') === 0) {
return
}
return `uni-app:///${filepath}`
}
}
const exclude = [/pages\.json/, /node_modules/, /vue&type=template/, /vue&type=style/]
module.exports = {
createSourceMapDevToolPlugin (filename = false) {
const options = {
test: [/\.js$/],
exclude,
moduleFilenameTemplate
}
if (filename) {
options.filename = '../.sourcemap/' + process.env.UNI_PLATFORM + '/[name].js.map'
}
return new webpack.SourceMapDevToolPlugin(options)
},
createEvalSourceMapDevToolPlugin () {
return new webpack.EvalSourceMapDevToolPlugin({
test: genTranspileDepRegex(process.env.UNI_INPUT_DIR),
exclude,
moduleFilenameTemplate
})
}
}
...@@ -16,10 +16,5 @@ module.exports = { ...@@ -16,10 +16,5 @@ module.exports = {
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['mycomponents'] return ['mycomponents']
},
configureWebpack () {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map'
}
} }
} }
...@@ -16,10 +16,5 @@ module.exports = { ...@@ -16,10 +16,5 @@ module.exports = {
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['swancomponents'] return ['swancomponents']
},
configureWebpack () {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map'
}
} }
} }
...@@ -37,10 +37,5 @@ module.exports = { ...@@ -37,10 +37,5 @@ module.exports = {
}) })
} }
return copyOptions return copyOptions
},
configureWebpack () {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map'
}
} }
} }
...@@ -13,10 +13,5 @@ module.exports = { ...@@ -13,10 +13,5 @@ module.exports = {
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['ttcomponents'] return ['ttcomponents']
},
configureWebpack () {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map'
}
} }
} }
...@@ -37,10 +37,5 @@ module.exports = { ...@@ -37,10 +37,5 @@ module.exports = {
}) })
} }
return copyOptions return copyOptions
},
configureWebpack () {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map'
}
} }
} }
...@@ -51,10 +51,5 @@ module.exports = { ...@@ -51,10 +51,5 @@ module.exports = {
} }
return copyOptions return copyOptions
},
configureWebpack () {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map'
}
} }
} }
...@@ -11,10 +11,6 @@ const { ...@@ -11,10 +11,6 @@ const {
getTemplatePath getTemplatePath
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const {
devtoolModuleFilenameTemplate
} = require('../util')
const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3 const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3
? require('../packages/webpack-app-plus-plugin') ? require('../packages/webpack-app-plus-plugin')
: require('../packages/webpack-app-plus-nvue-plugin') : require('../packages/webpack-app-plus-nvue-plugin')
...@@ -100,6 +96,10 @@ const plugins = [ ...@@ -100,6 +96,10 @@ const plugins = [
new WebpackAppPlusNVuePlugin() new WebpackAppPlusNVuePlugin()
] ]
if (process.env.NODE_ENV === 'development') {
plugins.push(require('@dcloudio/uni-cli-shared/lib/source-map').createEvalSourceMapDevToolPlugin())
}
// const excludeModuleReg = /node_modules(?!(\/|\\).*(weex).*)/ // const excludeModuleReg = /node_modules(?!(\/|\\).*(weex).*)/
const rules = [{ const rules = [{
...@@ -226,7 +226,7 @@ module.exports = function () { ...@@ -226,7 +226,7 @@ module.exports = function () {
return { return {
target: 'node', // 激活 vue-loader 的 isServer 逻辑 target: 'node', // 激活 vue-loader 的 isServer 逻辑
mode: process.env.NODE_ENV, mode: process.env.NODE_ENV,
devtool: process.env.NODE_ENV === 'development' ? 'inline-source-map' : false, devtool: false,
watch: process.env.NODE_ENV === 'development', watch: process.env.NODE_ENV === 'development',
entry () { entry () {
return process.UNI_NVUE_ENTRY return process.UNI_NVUE_ENTRY
...@@ -242,8 +242,7 @@ module.exports = function () { ...@@ -242,8 +242,7 @@ module.exports = function () {
}, },
output: { output: {
path: process.env.UNI_OUTPUT_DIR, path: process.env.UNI_OUTPUT_DIR,
filename: '[name].js', filename: '[name].js'
devtoolModuleFilenameTemplate
}, },
resolve: { resolve: {
extensions: ['.js', '.nvue', '.vue', '.json'], extensions: ['.js', '.nvue', '.vue', '.json'],
...@@ -323,4 +322,4 @@ module.exports = function () { ...@@ -323,4 +322,4 @@ module.exports = function () {
zlib: false zlib: false
} }
} }
} }
...@@ -30,13 +30,6 @@ module.exports = (api, options) => { // 仅处理 app-plus 相关逻辑 ...@@ -30,13 +30,6 @@ module.exports = (api, options) => { // 仅处理 app-plus 相关逻辑
plugins.push(new WebpackAppPlusPlugin()) plugins.push(new WebpackAppPlusPlugin())
const {
devtoolModuleFilenameTemplate
} = require('./util')
// sourcemap 输出相对路径
output.devtoolModuleFilenameTemplate = devtoolModuleFilenameTemplate
api.configureWebpack(webpackConfig => { api.configureWebpack(webpackConfig => {
return { return {
output, output,
......
const isWin = /^win/.test(process.platform) const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const METHODS = ['error', 'warn', 'info', 'log', 'debug'] const METHODS = ['error', 'warn', 'info', 'log', 'debug']
const FORMAT_LOG = '__f__' const FORMAT_LOG = '__f__'
module.exports = function({ module.exports = function ({
types: t types: t
}) { }) {
return { return {
visitor: { visitor: {
CallExpression(path, state) { CallExpression (path, state) {
const opts = state.opts const opts = state.opts
if (path.node.callee.object && if (path.node.callee.object &&
path.node.callee.object.name === 'console' && path.node.callee.object.name === 'console' &&
METHODS.includes(path.node.callee.property.name)) { METHODS.includes(path.node.callee.property.name)) {
if (path.node.callee.property.name === 'debug') { //console.debug=>console.log if (path.node.callee.property.name === 'debug') { // console.debug=>console.log
path.node.callee.property.name = 'log' path.node.callee.property.name = 'log'
} }
...@@ -49,7 +48,6 @@ module.exports = function({ ...@@ -49,7 +48,6 @@ module.exports = function({
} }
} }
} }
} }
} }
} }
......
...@@ -3,8 +3,7 @@ const { ...@@ -3,8 +3,7 @@ const {
} = require('@vue/cli-shared-utils') } = require('@vue/cli-shared-utils')
class WebpackAppPlusNVuePlugin { class WebpackAppPlusNVuePlugin {
apply(compiler) { apply (compiler) {
let isFirst = !process.env.UNI_USING_NATIVE && !process.env.UNI_USING_V3_NATIVE let isFirst = !process.env.UNI_USING_NATIVE && !process.env.UNI_USING_V3_NATIVE
const chunkVersions = {} const chunkVersions = {}
...@@ -35,12 +34,12 @@ class WebpackAppPlusNVuePlugin { ...@@ -35,12 +34,12 @@ class WebpackAppPlusNVuePlugin {
changedFiles.length > 0 && changedFiles.length > 0 &&
!changedFiles.find(file => file === 'app-config.js' || file === 'app-service.js') !changedFiles.find(file => file === 'app-config.js' || file === 'app-service.js')
) { ) {
done(`Build complete. PAGES:` + JSON.stringify(changedFiles)) done('Build complete. PAGES:' + JSON.stringify(changedFiles))
} else { } else {
done(`Build complete. Watching for changes...`) done('Build complete. Watching for changes...')
} }
} else { } else {
done(`Build complete. `) done('Build complete. ')
} }
} }
resolve() resolve()
......
...@@ -10,7 +10,6 @@ let nvueCompiled = true ...@@ -10,7 +10,6 @@ let nvueCompiled = true
let serviceCompiled = true let serviceCompiled = true
let viewCompiled = true let viewCompiled = true
const nvueChangedFiles = [] const nvueChangedFiles = []
const serviceChangedFiles = [] const serviceChangedFiles = []
const viewChangedFiles = [] const viewChangedFiles = []
...@@ -19,9 +18,8 @@ let isFirst = true ...@@ -19,9 +18,8 @@ let isFirst = true
let compiling = false let compiling = false
class WebpackAppPlusPlugin { class WebpackAppPlusPlugin {
apply(compiler) { apply (compiler) {
if (process.env.UNI_USING_V3) { if (process.env.UNI_USING_V3) {
const chunkVersions = {} const chunkVersions = {}
const entry = compiler.options.entry() const entry = compiler.options.entry()
...@@ -30,7 +28,6 @@ class WebpackAppPlusPlugin { ...@@ -30,7 +28,6 @@ class WebpackAppPlusPlugin {
const isAppNVue = !isAppService && !isAppView const isAppNVue = !isAppService && !isAppView
compiler.hooks.invalid.tap('WebpackAppPlusPlugin', (fileName, changeTime) => { compiler.hooks.invalid.tap('WebpackAppPlusPlugin', (fileName, changeTime) => {
if (!compiling) { if (!compiling) {
compiling = true compiling = true
...@@ -82,16 +79,16 @@ class WebpackAppPlusPlugin { ...@@ -82,16 +79,16 @@ class WebpackAppPlusPlugin {
if (!isFirst && changedFiles.length > 0) { if (!isFirst && changedFiles.length > 0) {
if (serviceChangedFiles.length === 0 && viewChangedFiles.length === 0) { if (serviceChangedFiles.length === 0 && viewChangedFiles.length === 0) {
// 仅 nvue 页面发生变化 // 仅 nvue 页面发生变化
done(`Build complete. PAGES:` + JSON.stringify(changedFiles)) done('Build complete. PAGES:' + JSON.stringify(changedFiles))
} else { } else {
done(`Build complete. FILES:` + JSON.stringify(changedFiles)) done('Build complete. FILES:' + JSON.stringify(changedFiles))
} }
} else { } else {
!process.env.UNI_AUTOMATOR_WS_ENDPOINT && done(`Build complete. Watching for changes...`) !process.env.UNI_AUTOMATOR_WS_ENDPOINT && done('Build complete. Watching for changes...')
} }
isFirst = false isFirst = false
} else { } else {
done(`Build complete. `) done('Build complete. ')
} }
nvueChangedFiles.length = 0 nvueChangedFiles.length = 0
serviceChangedFiles.length = 0 serviceChangedFiles.length = 0
...@@ -103,21 +100,20 @@ class WebpackAppPlusPlugin { ...@@ -103,21 +100,20 @@ class WebpackAppPlusPlugin {
}) })
} else { } else {
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => { compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
return resolve() return resolve()
} }
const callback = function() { const callback = function () {
fs.copyFileSync(path.resolve(process.env.UNI_OUTPUT_TMP_DIR, fs.copyFileSync(path.resolve(process.env.UNI_OUTPUT_TMP_DIR,
'manifest.json'), 'manifest.json'),
path.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json')) path.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json'))
log() log()
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
done(`Build complete. Watching for changes...`) done('Build complete. Watching for changes...')
} else { } else {
done(`Build complete. `) done('Build complete. ')
} }
resolve() resolve()
} }
......
...@@ -17,14 +17,14 @@ const { ...@@ -17,14 +17,14 @@ const {
const appVuePath = path.resolve(process.env.UNI_INPUT_DIR, 'App.vue') const appVuePath = path.resolve(process.env.UNI_INPUT_DIR, 'App.vue')
function genStyleRequest(style, i, stringifyRequest) { function genStyleRequest (style, i, stringifyRequest) {
const src = style.src || normalizePath(appVuePath) const src = style.src || normalizePath(appVuePath)
const attrsQuery = attrsToQuery(style.attrs, 'css') const attrsQuery = attrsToQuery(style.attrs, 'css')
const query = `?vue&type=style&index=${i}${attrsQuery}` const query = `?vue&type=style&index=${i}${attrsQuery}`
return stringifyRequest(src + query) return stringifyRequest(src + query)
} }
function getAppStyleCode(stringifyRequest) { function getAppStyleCode (stringifyRequest) {
if (!process.env.UNI_USING_NVUE_COMPILER) { if (!process.env.UNI_USING_NVUE_COMPILER) {
return '' return ''
} }
...@@ -37,17 +37,17 @@ function getAppStyleCode(stringifyRequest) { ...@@ -37,17 +37,17 @@ function getAppStyleCode(stringifyRequest) {
} catch (e) {} } catch (e) {}
styles.forEach((style, index) => { styles.forEach((style, index) => {
code = code + code = code +
`Vue.prototype.__merge_style && Vue.prototype.__merge_style(require(${genStyleRequest(style,index,stringifyRequest)}).default,Vue.prototype.__$appStyle__)\n` `Vue.prototype.__merge_style && Vue.prototype.__merge_style(require(${genStyleRequest(style, index, stringifyRequest)}).default,Vue.prototype.__$appStyle__)\n`
}) })
return code return code
} }
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const loaderContext = this const loaderContext = this
const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : '' const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
if (this.resourceQuery) { if (this.resourceQuery) {
const params = loaderUtils.parseQuery(this.resourceQuery) const params = loaderUtils.parseQuery(this.resourceQuery)
...@@ -69,7 +69,6 @@ module.exports = function(content) { ...@@ -69,7 +69,6 @@ module.exports = function(content) {
return `${getAppStyleCode(stringifyRequest)}` return `${getAppStyleCode(stringifyRequest)}`
} }
} }
} }
return statCode + content return statCode + content
} }
var path = require('path') var path = require('path')
var styler = require('weex-styler') var styler = require('weex-styler')
var { var {
normalizePath normalizePath
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
return 'module.exports = ' + genStyleString(content.replace(/\!important/g, ''), this) this.callback(null, 'module.exports = ' + genStyleString(content.replace(/!important/g, ''), this), map)
} }
// @todo: // @todo:
...@@ -14,57 +14,57 @@ module.exports = function(content) { ...@@ -14,57 +14,57 @@ module.exports = function(content) {
// https://drafts.csswg.org/css-values/#lengths // https://drafts.csswg.org/css-values/#lengths
var REGEXP_LENGTH = /^([-+]?[0-9]*\.?[0-9]+)(rem|vw|vh|vmin|vmax|cm|mm|q|in|pt|pc|px)$/ var REGEXP_LENGTH = /^([-+]?[0-9]*\.?[0-9]+)(rem|vw|vh|vmin|vmax|cm|mm|q|in|pt|pc|px)$/
function convertLength(k, v) { function convertLength (k, v) {
if (typeof v !== 'string') { if (typeof v !== 'string') {
return v
}
var result = v.match(REGEXP_LENGTH)
if (result) {
if (result[2] === 'px') {
return result[1]
}
return result[1] + 'CSS_UNIT_' + result[2].toUpperCase()
}
return v return v
}
var result = v.match(REGEXP_LENGTH)
if (result) {
if (result[2] === 'px') {
return result[1]
}
return result[1] + 'CSS_UNIT_' + result[2].toUpperCase()
}
return v
} }
let isFirst = true let isFirst = true
function genStyleString(input, loader) { function genStyleString (input, loader) {
var output = '{}' var output = '{}'
var resourcePath = normalizePath(path.relative(process.env.UNI_INPUT_DIR, loader.resourcePath)) var resourcePath = normalizePath(path.relative(process.env.UNI_INPUT_DIR, loader.resourcePath))
styler.parse(input, function(err, obj) { styler.parse(input, function (err, obj) {
if (err) { if (err) {
loader.emitError(err) loader.emitError(err)
return return
} }
if (obj && obj.jsonStyle) { if (obj && obj.jsonStyle) {
if (obj.log) { if (obj.log) {
var msgs = [] var msgs = []
obj.log.map((log) => { obj.log.map((log) => {
if (log.reason.indexOf('NOTE:') !== 0) { //仅显示警告,错误信息 if (log.reason.indexOf('NOTE:') !== 0) { // 仅显示警告,错误信息
if (log.selectors) { if (log.selectors) {
msgs.push(`${log.selectors}: ${log.reason} at ${resourcePath}:${log.line}`) msgs.push(`${log.selectors}: ${log.reason} at ${resourcePath}:${log.line}`)
} else { } else {
msgs.push(`${log.reason} at ${resourcePath}:${log.line}`) msgs.push(`${log.reason} at ${resourcePath}:${log.line}`)
}
}
})
if (msgs.length) {
if (isFirst) {
msgs.unshift(
`nvue中不支持如下css。如全局或公共样式受影响,建议将告警样式写在ifndef APP-PLUS-NVUE的条件编译中,详情如下:`
)
isFirst = false
}
msgs.forEach(msg => console.warn(msg))
}
} }
try { }
output = JSON.stringify(obj.jsonStyle, convertLength, 2) })
.replace(/"([-+]?[0-9]*\.?[0-9]+)CSS_UNIT_([A-Z]+)"/g, '$1 * CSS_UNIT.$2') if (msgs.length) {
} catch (e) {} if (isFirst) {
msgs.unshift(
'nvue中不支持如下css。如全局或公共样式受影响,建议将告警样式写在ifndef APP-PLUS-NVUE的条件编译中,详情如下:'
)
isFirst = false
}
msgs.forEach(msg => console.warn(msg))
} }
}) }
return output try {
output = JSON.stringify(obj.jsonStyle, convertLength, 2)
.replace(/"([-+]?[0-9]*\.?[0-9]+)CSS_UNIT_([A-Z]+)"/g, '$1 * CSS_UNIT.$2')
} catch (e) {}
}
})
return output
} }
...@@ -17,15 +17,15 @@ const SCROLLER_COMPONENTS = [ ...@@ -17,15 +17,15 @@ const SCROLLER_COMPONENTS = [
'waterfall' 'waterfall'
] ]
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const source = content.trim() const source = content.trim()
if (SCROLLER_COMPONENTS.find(name => source.indexOf('<' + name) === 0)) { if (SCROLLER_COMPONENTS.find(name => source.indexOf('<' + name) === 0)) {
return content return this.callback(null, content, map)
} }
if (source.indexOf('<recycle-list') !== -1) { if (source.indexOf('<recycle-list') !== -1) {
return content return this.callback(null, content, map)
} }
let resourcePath = normalizeNodeModules( let resourcePath = normalizeNodeModules(
...@@ -44,15 +44,15 @@ module.exports = function(content) { ...@@ -44,15 +44,15 @@ module.exports = function(content) {
} }
if (!process.UNI_NVUE_ENTRY[resourcePath]) { if (!process.UNI_NVUE_ENTRY[resourcePath]) {
return content return this.callback(null, content, map)
} }
// 暂时实时读取配置信息,查找是否 disableScroll // 暂时实时读取配置信息,查找是否 disableScroll
const appJson = getPagesJson() const appJson = getPagesJson()
let pageJson let pageJson
if (appJson.nvue) { //旧版本 if (appJson.nvue) { // 旧版本
if (!appJson.nvue || !appJson.nvue.pages) { if (!appJson.nvue || !appJson.nvue.pages) {
return content return this.callback(null, content, map)
} }
const pagePath = resourcePath + '.html' const pagePath = resourcePath + '.html'
pageJson = appJson.nvue.pages.find(page => page.path === pagePath) pageJson = appJson.nvue.pages.find(page => page.path === pagePath)
...@@ -61,7 +61,7 @@ module.exports = function(content) { ...@@ -61,7 +61,7 @@ module.exports = function(content) {
} }
if (!pageJson) { if (!pageJson) {
return content return this.callback(null, content, map)
} }
if (!appJson.globalStyle) { if (!appJson.globalStyle) {
...@@ -72,8 +72,10 @@ module.exports = function(content) { ...@@ -72,8 +72,10 @@ module.exports = function(content) {
Object.assign(pageJson.style, pageJson.style['app-plus'] || {}) Object.assign(pageJson.style, pageJson.style['app-plus'] || {})
const pageJsonStyle = Object.assign(appJson.globalStyle, pageJson.style) const pageJsonStyle = Object.assign(appJson.globalStyle, pageJson.style)
if (pageJsonStyle.disableScroll === true) { if (pageJsonStyle.disableScroll === true) {
return content return this.callback(null, content, map)
} }
return `<scroll-view :scroll-y="true" :show-scrollbar="${pageJsonStyle.scrollIndicator==='none'?'false':'true'}" :enableBackToTop="true" bubble="true" style="flex-direction:column">${content}</scroll-view>` this.callback(null,
`<scroll-view :scroll-y="true" :show-scrollbar="${pageJsonStyle.scrollIndicator === 'none' ? 'false' : 'true'}" :enableBackToTop="true" bubble="true" style="flex-direction:column">${content}</scroll-view>`,
map)
} }
const loaderUtils = require('loader-utils') const loaderUtils = require('loader-utils')
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options') const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options')
...@@ -14,5 +14,5 @@ module.exports = function(content) { ...@@ -14,5 +14,5 @@ module.exports = function(content) {
throw new Error('vue-loader-options parse error') throw new Error('vue-loader-options parse error')
} }
return content this.callback(null, content, map)
} }
const path = require('path')
const {
normalizePath,
isInHBuilderX
} = require('@dcloudio/uni-cli-shared/lib/util')
let sourceRoot = false
function devtoolModuleFilenameTemplate (info) {
if (!sourceRoot) {
if (isInHBuilderX) {
sourceRoot = normalizePath(process.env.UNI_INPUT_DIR)
} else {
sourceRoot = normalizePath(process.env.UNI_CLI_CONTEXT)
}
}
let filePath = false
const absoluteResourcePath = normalizePath(info.absoluteResourcePath)
if (
absoluteResourcePath.indexOf(sourceRoot) !== -1 &&
(
absoluteResourcePath.endsWith('.js') ||
absoluteResourcePath.endsWith('.ts')
)
) {
filePath = normalizePath(path.relative(sourceRoot, absoluteResourcePath))
if (
filePath.indexOf('node_modules/@dcloudio') === 0 ||
filePath.indexOf('node_modules/vue-loader') === 0 ||
filePath.indexOf('node_modules/webpack') === 0
) {
filePath = false
}
} else if (
!info.moduleId &&
(
absoluteResourcePath.endsWith('.vue') ||
absoluteResourcePath.endsWith('.nvue')
)
) {
if (
absoluteResourcePath.indexOf('src') !== 0 &&
absoluteResourcePath.indexOf('node-modules') !== 0
) {
filePath = normalizePath(path.relative(sourceRoot, absoluteResourcePath))
} else {
filePath = absoluteResourcePath
}
}
if (
filePath &&
filePath !== 'main.js' &&
filePath !== 'main.ts' &&
filePath !== 'src/main.js' &&
filePath !== 'src/main.ts'
) {
return `uni-app:///${filePath}`
}
}
module.exports = {
devtoolModuleFilenameTemplate
}
...@@ -8,12 +8,12 @@ process.UNI_APIS = new Set() ...@@ -8,12 +8,12 @@ process.UNI_APIS = new Set()
const sourcePath = normalizePath(path.join(require.resolve('@dcloudio/uni-h5'), '../../')) const sourcePath = normalizePath(path.join(require.resolve('@dcloudio/uni-h5'), '../../'))
module.exports = function({ module.exports = function ({
types: t types: t
}) { }) {
return { return {
visitor: { visitor: {
MemberExpression(path, state) { MemberExpression (path, state) {
if ( if (
t.isIdentifier(path.node.object) && t.isIdentifier(path.node.object) &&
( (
......
...@@ -4,24 +4,24 @@ const updateComponents = require('./component') ...@@ -4,24 +4,24 @@ const updateComponents = require('./component')
const tmpDir = path.resolve(__dirname, '../../.tmp') const tmpDir = path.resolve(__dirname, '../../.tmp')
function writeFileSync(filename, content) { function writeFileSync (filename, content) {
fs.writeFileSync(path.resolve(tmpDir, filename), content, 'utf8') fs.writeFileSync(path.resolve(tmpDir, filename), content, 'utf8')
} }
function parseImportPath(filepath) { function parseImportPath (filepath) {
if (filepath.indexOf('/platforms') === 0) { //api,appComponents(h5),appMixins(h5),systemRoutes(h5) if (filepath.indexOf('/platforms') === 0) { // api,appComponents(h5),appMixins(h5),systemRoutes(h5)
return filepath.replace('/platforms/' + process.env.UNI_PLATFORM, 'uni-platform') return filepath.replace('/platforms/' + process.env.UNI_PLATFORM, 'uni-platform')
} else if (filepath.indexOf('/core/helpers') === 0) { //protocol } else if (filepath.indexOf('/core/helpers') === 0) { // protocol
return filepath.replace('/core/helpers', 'uni-helpers') return filepath.replace('/core/helpers', 'uni-helpers')
} else if (filepath.indexOf('/core/view') === 0) { //subscribe } else if (filepath.indexOf('/core/view') === 0) { // subscribe
return filepath.replace('/core/view', 'uni-view') return filepath.replace('/core/view', 'uni-view')
} else if (filepath.indexOf('/core') === 0) { //api } else if (filepath.indexOf('/core') === 0) { // api
return filepath.replace('/core', 'uni-core') return filepath.replace('/core', 'uni-core')
} }
return filepath return filepath
} }
function updateExportDefaultObject(paths, filename, isMulti = true, isExportArray = false) { function updateExportDefaultObject (paths, filename, isMulti = true, isExportArray = false) {
const imports = [] const imports = []
const exports = [] const exports = []
Object.keys(paths).forEach(name => { Object.keys(paths).forEach(name => {
...@@ -32,7 +32,7 @@ function updateExportDefaultObject(paths, filename, isMulti = true, isExportArra ...@@ -32,7 +32,7 @@ function updateExportDefaultObject(paths, filename, isMulti = true, isExportArra
} }
exports.push(name) exports.push(name)
}) })
let content = isExportArray ? `export default []` : `export default {}` let content = isExportArray ? 'export default []' : 'export default {}'
if (exports.length) { if (exports.length) {
if (isExportArray) { if (isExportArray) {
content = ` content = `
...@@ -53,37 +53,37 @@ function updateExportDefaultObject(paths, filename, isMulti = true, isExportArra ...@@ -53,37 +53,37 @@ function updateExportDefaultObject(paths, filename, isMulti = true, isExportArra
writeFileSync(filename, content) writeFileSync(filename, content)
} }
function updateApi(paths) { function updateApi (paths) {
return updateExportDefaultObject(paths, 'api.js') return updateExportDefaultObject(paths, 'api.js')
} }
function updateApiProtocol(paths) { function updateApiProtocol (paths) {
return updateExportDefaultObject(paths, 'protocol.js') return updateExportDefaultObject(paths, 'protocol.js')
} }
function updateApiSubscribe(paths) { function updateApiSubscribe (paths) {
return updateExportDefaultObject(paths, 'subscribe.js') return updateExportDefaultObject(paths, 'subscribe.js')
} }
function updateInvokeApi(paths) { function updateInvokeApi (paths) {
return updateExportDefaultObject(paths, 'invoke-api.js') return updateExportDefaultObject(paths, 'invoke-api.js')
} }
function updateAppComponents(paths) { function updateAppComponents (paths) {
return updateExportDefaultObject(paths, 'app-components.js', false) return updateExportDefaultObject(paths, 'app-components.js', false)
} }
function updateCoreComponents(paths){ function updateCoreComponents (paths) {
const tags = process.UNI_TAGS || new Set() const tags = process.UNI_TAGS || new Set()
Object.keys(paths).forEach(tag => tags.add(tag.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase())) Object.keys(paths).forEach(tag => tags.add(tag.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()))
updateComponents(tags) updateComponents(tags)
} }
function updateAppMixins(paths) { function updateAppMixins (paths) {
return updateExportDefaultObject(paths, 'app-mixins.js', false, true) return updateExportDefaultObject(paths, 'app-mixins.js', false, true)
} }
function updateSystemRoutes(paths) { function updateSystemRoutes (paths) {
return updateExportDefaultObject(paths, 'system-routes.js', false) return updateExportDefaultObject(paths, 'system-routes.js', false)
} }
...@@ -118,9 +118,7 @@ const isApiSubscribe = filepath => { ...@@ -118,9 +118,7 @@ const isApiSubscribe = filepath => {
return filepath.indexOf('/core/view/bridge/subscribe/api') === 0 return filepath.indexOf('/core/view/bridge/subscribe/api') === 0
} }
function parseDeps (apis, manifest) {
function parseDeps(apis, manifest) {
const apiPaths = Object.create(null) const apiPaths = Object.create(null)
const apiProtocolPaths = Object.create(null) const apiProtocolPaths = Object.create(null)
const invokeApiPaths = Object.create(null) const invokeApiPaths = Object.create(null)
...@@ -152,7 +150,7 @@ function parseDeps(apis, manifest) { ...@@ -152,7 +150,7 @@ function parseDeps(apis, manifest) {
test: isApiSubscribe, test: isApiSubscribe,
paths: apiSubscribePaths paths: apiSubscribePaths
}] }]
for (let name of apis.values()) { for (const name of apis.values()) {
const options = manifest[name] const options = manifest[name]
if (Array.isArray(options)) { if (Array.isArray(options)) {
apiPaths[name] = options[0] apiPaths[name] = options[0]
...@@ -167,7 +165,7 @@ function parseDeps(apis, manifest) { ...@@ -167,7 +165,7 @@ function parseDeps(apis, manifest) {
const filepath = dep[0] const filepath = dep[0]
const exports = dep[1] const exports = dep[1]
if (isCoreApi && isPlatformApi(filepath)) { //invoke-api if (isCoreApi && isPlatformApi(filepath)) { // invoke-api
invokeApiPaths[exports] = filepath invokeApiPaths[exports] = filepath
} else { } else {
const strategy = strategies.find(strategy => { const strategy = strategies.find(strategy => {
...@@ -176,7 +174,7 @@ function parseDeps(apis, manifest) { ...@@ -176,7 +174,7 @@ function parseDeps(apis, manifest) {
if (strategy) { if (strategy) {
strategy.paths[exports] = filepath strategy.paths[exports] = filepath
} else { } else {
console.log('dep',name,dep) console.log('dep', name, dep)
console.warn(`${filepath} 未识别`) console.warn(`${filepath} 未识别`)
} }
} }
...@@ -198,8 +196,7 @@ function parseDeps(apis, manifest) { ...@@ -198,8 +196,7 @@ function parseDeps(apis, manifest) {
} }
} }
module.exports = function updateApis(apis = new Set(), userApis = new Set()) { module.exports = function updateApis (apis = new Set(), userApis = new Set()) {
if (!fs.existsSync(tmpDir)) { if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir) fs.mkdirSync(tmpDir)
} }
......
...@@ -16,7 +16,7 @@ const autoloadTags = { ...@@ -16,7 +16,7 @@ const autoloadTags = {
} }
} }
module.exports = function updateComponents(tags) { module.exports = function updateComponents (tags) {
autoloadTags.root.forEach(tagName => { autoloadTags.root.forEach(tagName => {
tags.add(tagName) tags.add(tagName)
}) })
...@@ -54,6 +54,5 @@ ${componentsStr} ...@@ -54,6 +54,5 @@ ${componentsStr}
fs.mkdirSync(dir) fs.mkdirSync(dir)
} }
fs.writeFileSync(path.resolve(dir, 'components.js'), content, 'utf8') fs.writeFileSync(path.resolve(dir, 'components.js'), content, 'utf8')
} }
const fs = require('fs')
const path = require('path')
const { const {
info, info,
done, done
} = require('@vue/cli-shared-utils') } = require('@vue/cli-shared-utils')
const updateComponents = require('./component') const updateComponents = require('./component')
const updateApis = require('./api') const updateApis = require('./api')
class WebpackOptimizePlugin { class WebpackOptimizePlugin {
apply(compiler) { apply (compiler) {
let optimized = false let optimized = false
compiler.hooks.beforeCompile.tapPromise('WebpackOptimizePlugin', compilation => { compiler.hooks.beforeCompile.tapPromise('WebpackOptimizePlugin', compilation => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -28,12 +25,12 @@ class WebpackOptimizePlugin { ...@@ -28,12 +25,12 @@ class WebpackOptimizePlugin {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!optimized) { if (!optimized) {
console.log() console.log()
info(`Build optimizing...`) info('Build optimizing...')
optimized = true optimized = true
updateComponents(process.UNI_TAGS || new Set()) updateComponents(process.UNI_TAGS || new Set())
updateApis(process.UNI_APIS || new Set(), process.UNI_USER_APIS || new Set()) updateApis(process.UNI_APIS || new Set(), process.UNI_USER_APIS || new Set())
} else { } else {
done(`Build complete.`) done('Build complete.')
process.exit(0) process.exit(0)
} }
resolve() resolve()
......
function cached(fn) { function cached (fn) {
const cache = Object.create(null) const cache = Object.create(null)
return function cachedFn(str) { return function cachedFn (str) {
const hit = cache[str] const hit = cache[str]
return hit || (cache[str] = fn(str)) return hit || (cache[str] = fn(str))
} }
...@@ -8,11 +8,11 @@ function cached(fn) { ...@@ -8,11 +8,11 @@ function cached(fn) {
const camelizeRE = /-(\w)/g const camelizeRE = /-(\w)/g
const camelize = cached(function(str) { const camelize = cached(function (str) {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}) })
const capitalize = cached(function(str) { const capitalize = cached(function (str) {
return str.charAt(0).toUpperCase() + str.slice(1) return str.charAt(0).toUpperCase() + str.slice(1)
}) })
......
...@@ -5,11 +5,11 @@ const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) ...@@ -5,11 +5,11 @@ const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const src = require('@dcloudio/uni-h5/path').src const src = require('@dcloudio/uni-h5/path').src
module.exports = function (content) { module.exports = function (content) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const resourcePath = normalizePath(this.resourcePath) const resourcePath = normalizePath(this.resourcePath)
const sourcePath = normalizePath(src) const sourcePath = normalizePath(src)
if (resourcePath.indexOf(sourcePath) === 0) { if (resourcePath.indexOf(sourcePath) === 0) {
return '' return ''
} }
return content return content
} }
...@@ -263,7 +263,26 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt ...@@ -263,7 +263,26 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}) })
} }
if (process.env.NODE_ENV === 'development') {
const sourceMap = require('@dcloudio/uni-cli-shared/lib/source-map')
let isAppService = false
if (process.env.UNI_PLATFORM === 'app-plus' && vueOptions.pluginOptions['uni-app-plus']) {
isAppService = !!vueOptions.pluginOptions['uni-app-plus'].service
}
if (process.env.UNI_PLATFORM === 'h5' || isAppService) {
plugins.push(sourceMap.createEvalSourceMapDevToolPlugin())
} else if (
process.env.UNI_PLATFORM.indexOf('mp-') === 0 &&
process.env.UNI_PLATFORM !== 'mp-baidu' &&
process.env.UNI_PLATFORM !== 'mp-alipay' &&
process.env.UNI_PLATFORM !== 'quickapp-webview' // 目前 ov 的开发工具支持 eval 模式
) {
plugins.push(sourceMap.createSourceMapDevToolPlugin(process.env.UNI_PLATFORM === 'mp-weixin'))
}
}
return merge({ return merge({
devtool: false,
resolve: { resolve: {
alias: { alias: {
'@': path.resolve(process.env.UNI_INPUT_DIR), '@': path.resolve(process.env.UNI_INPUT_DIR),
......
...@@ -15,7 +15,7 @@ function shouldReport (err = '') { ...@@ -15,7 +15,7 @@ function shouldReport (err = '') {
// err:string|Error // err:string|Error
function report (type, err) { function report (type, err) {
if (shouldReport(err)) { if (shouldReport(err)) {
console.log('Error Reporting...') // console.log('Error Reporting...')
// const https = require('https') // const https = require('https')
// const data = ... // const data = ...
// const req = https.request({ // const req = https.request({
......
...@@ -89,8 +89,8 @@ module.exports = { ...@@ -89,8 +89,8 @@ module.exports = {
output: { output: {
filename: '[name].js', filename: '[name].js',
chunkFilename: '[id].js', chunkFilename: '[id].js',
globalObject: process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global', globalObject: process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global'
sourceMapFilename: '../.sourcemap/' + process.env.UNI_PLATFORM + '/[name].js.map' // sourceMapFilename: '../.sourcemap/' + process.env.UNI_PLATFORM + '/[name].js.map'
}, },
performance: { performance: {
hints: false hints: false
......
...@@ -70,7 +70,7 @@ if (process.env.UNI_USING_V3) { ...@@ -70,7 +70,7 @@ if (process.env.UNI_USING_V3) {
let cssVarValue = false let cssVarValue = false
walk(node.nodes, n => { walk(node.nodes, n => {
if (n.type === 'word') { if (n.type === 'word') {
if (cssVars.hasOwnProperty(n.value)) { // 目前仅考虑 nodes 长度为0 if (Object.prototype.hasOwnProperty.call(cssVars, n.value)) { // 目前仅考虑 nodes 长度为0
cssVarValue = cssVars[n.value] cssVarValue = cssVars[n.value]
} }
} }
......
module.exports = { module.exports = {
'br': 'r', br: 'r',
'hr': 'r', hr: 'r',
'p': 'r', p: 'r',
'h1': 'r', h1: 'r',
'h2': 'r', h2: 'r',
'h3': 'r', h3: 'r',
'h4': 'r', h4: 'r',
'h5': 'r', h5: 'r',
'h6': 'r', h6: 'r',
'abbr': 'r', abbr: 'r',
'address': 'r', address: 'r',
'b': 'r', b: 'r',
'bdi': 'r', bdi: 'r',
'bdo': 'r', bdo: 'r',
'blockquote': 'r', blockquote: 'r',
'cite': 'r', cite: 'r',
'code': 'r', code: 'r',
'del': 'r', del: 'r',
'ins': 'r', ins: 'r',
'dfn': 'r', dfn: 'r',
'em': 'r', em: 'r',
'strong': 'r', strong: 'r',
'samp': 'r', samp: 'r',
'kbd': 'r', kbd: 'r',
'var': 'r', var: 'r',
'i': 'r', i: 'r',
'mark': 'r', mark: 'r',
'pre': 'r', pre: 'r',
'q': 'r', q: 'r',
'ruby': 'r', ruby: 'r',
'rp': 'r', rp: 'r',
'rt': 'r', rt: 'r',
's': 'r', s: 'r',
'small': 'r', small: 'r',
'sub': 'r', sub: 'r',
'sup': 'r', sup: 'r',
'time': 'r', time: 'r',
'u': 'r', u: 'r',
'wbr': 'r', wbr: 'r',
// 表单元素 // 表单元素
// 'form': 'r', // 'form': 'r',
// 'input': 'r', // 'input': 'r',
// 'textarea': 'r', // 'textarea': 'r',
// 'button': 'r', // 'button': 'r',
'select': 'r', select: 'r',
'option': 'r', option: 'r',
'optgroup': 'r', optgroup: 'r',
// 'label': 'r', // 'label': 'r',
'fieldset': 'r', fieldset: 'r',
'datalist': 'r', datalist: 'r',
'legend': 'r', legend: 'r',
'output': 'r', output: 'r',
// 框架 // 框架
'iframe': 'r', iframe: 'r',
// 图像 // 图像
'img': 'r', img: 'r',
// 'canvas': 'r', // 'canvas': 'r',
'figure': 'r', figure: 'r',
'figcaption': 'r', figcaption: 'r',
// 音视频 // 音视频
// 'audio': 'r', // 'audio': 'r',
'source': 'r', source: 'r',
// 'video': 'r', // 'video': 'r',
'track': 'r', track: 'r',
// 链接 // 链接
'a': 'r', a: 'r',
'nav': 'r', nav: 'r',
'link': 'r', link: 'r',
// 列表 // 列表
'ul': 'r', ul: 'r',
'ol': 'r', ol: 'r',
'li': 'r', li: 'r',
'dl': 'r', dl: 'r',
'dt': 'r', dt: 'r',
'dd': 'r', dd: 'r',
'menu': 'r', menu: 'r',
'command': 'r', command: 'r',
// 表格table // 表格table
'table': 'r', table: 'r',
'caption': 'r', caption: 'r',
'th': 'r', th: 'r',
'td': 'r', td: 'r',
'tr': 'r', tr: 'r',
'thead': 'r', thead: 'r',
'tbody': 'r', tbody: 'r',
'tfoot': 'r', tfoot: 'r',
'col': 'r', col: 'r',
'colgroup': 'r', colgroup: 'r',
// 样式 节 // 样式 节
'div': 'r', div: 'r',
'main': 'r', main: 'r',
'span': 'r', span: 'r',
'header': 'r', header: 'r',
'footer': 'r', footer: 'r',
'section': 'r', section: 'r',
'article': 'r', article: 'r',
'aside': 'r', aside: 'r',
'details': 'r', details: 'r',
'dialog': 'r', dialog: 'r',
'summary': 'r', summary: 'r',
// 'progress': 'r', // 'progress': 'r',
'meter': 'r', // todo meter: 'r', // todo
'head': 'r', // todo head: 'r', // todo
'meta': 'r', // todo meta: 'r', // todo
'base': 'r', // todo base: 'r', // todo
// 'map': 'r', // TODO不是很恰当 // 'map': 'r', // TODO不是很恰当
'area': 'r', // j结合map使用 area: 'r', // j结合map使用
'script': 'r', script: 'r',
'noscript': 'r', noscript: 'r',
'embed': 'r', embed: 'r',
'object': 'r', object: 'r',
'param': 'r', param: 'r',
'body': 'page', body: 'page',
'html': 'page' html: 'page'
} }
...@@ -14,7 +14,7 @@ const { ...@@ -14,7 +14,7 @@ const {
const FILTER_TAG = getPlatformFilterTag() const FILTER_TAG = getPlatformFilterTag()
module.exports = function(source) { module.exports = function (source) {
const loaderContext = this const loaderContext = this
const { const {
......
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin')
class WebpackHtmlAppendPlugin { class WebpackHtmlAppendPlugin {
constructor(content) { constructor (content) {
this.content = content || '' this.content = content || ''
} }
apply(compiler) {
apply (compiler) {
compiler.hooks.compilation.tap('WebpackHtmlAppendPlugin', (compilation) => { compiler.hooks.compilation.tap('WebpackHtmlAppendPlugin', (compilation) => {
let beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing let beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing
if (!beforeEmit && HtmlWebpackPlugin.getHooks) { if (!beforeEmit && HtmlWebpackPlugin.getHooks) {
......
...@@ -8,17 +8,17 @@ const { ...@@ -8,17 +8,17 @@ const {
const preprocessor = require('./preprocess/lib/preprocess') const preprocessor = require('./preprocess/lib/preprocess')
const ERRORS = { const ERRORS = {
'html': `条件编译失败,参考示例(注意 ifdef 与 endif 必须配对使用): html: `条件编译失败,参考示例(注意 ifdef 与 endif 必须配对使用):
<!-- #ifdef %PLATFORM% --> <!-- #ifdef %PLATFORM% -->
模板代码 模板代码
<!-- #endif --> <!-- #endif -->
`, `,
'js': `条件编译失败,参考示例(注意 ifdef 与 endif 必须配对使用): js: `条件编译失败,参考示例(注意 ifdef 与 endif 必须配对使用):
// #ifdef %PLATFORM% // #ifdef %PLATFORM%
js代码 js代码
// #endif // #endif
`, `,
'css': `条件编译失败,参考示例(注意 ifdef 与 endif 必须配对使用): css: `条件编译失败,参考示例(注意 ifdef 与 endif 必须配对使用):
/* #ifdef %PLATFORM% */ /* #ifdef %PLATFORM% */
css代码 css代码
/* #endif */ /* #endif */
...@@ -26,9 +26,9 @@ css代码 ...@@ -26,9 +26,9 @@ css代码
} }
const TAGS = { const TAGS = {
'html': 'template', html: 'template',
'js': 'script', js: 'script',
'css': 'style' css: 'style'
} }
module.exports = function (content, map) { module.exports = function (content, map) {
......
...@@ -4,14 +4,14 @@ const isWin = /^win/.test(process.platform) ...@@ -4,14 +4,14 @@ const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const resourcePath = normalizePath(this.resourcePath) const resourcePath = normalizePath(this.resourcePath)
if ( if (
resourcePath !== normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'App.vue')) && resourcePath !== normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'App.vue')) &&
content.indexOf('platform="mp-weixin"') === -1 // 小程序组件暂不加scoped content.indexOf('platform="mp-weixin"') === -1 // 小程序组件暂不加scoped
) { ) {
return content.replace(/(<style\b[^><]*)>/ig, '$1 scoped>') return this.callback(null, content.replace(/(<style\b[^><]*)>/ig, '$1 scoped>'), map)
} }
return content this.callback(null, content, map)
} }
const loaderUtils = require('loader-utils') const loaderUtils = require('loader-utils')
function parseFilterModules(filterModules) { function parseFilterModules (filterModules) {
if (filterModules) { if (filterModules) {
return JSON.parse(Buffer.from(filterModules, 'base64').toString('utf8')) return JSON.parse(Buffer.from(filterModules, 'base64').toString('utf8'))
} }
return {} return {}
} }
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options') const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options')
...@@ -21,5 +21,5 @@ module.exports = function(content) { ...@@ -21,5 +21,5 @@ module.exports = function(content) {
} else { } else {
throw new Error('vue-loader-options parse error') throw new Error('vue-loader-options parse error')
} }
return content this.callback(null, content, map)
} }
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
// TODO 简单判断,只要包含 page-meta,就在外层包裹一层 view (vue2 不支持多 root) // TODO 简单判断,只要包含 page-meta,就在外层包裹一层 view (vue2 不支持多 root)
if (content.indexOf('<page-meta') !== -1) { if (content.indexOf('<page-meta') !== -1) {
return `<view>${content}</view>` return this.callback(null, `<view>${content}</view>`, map)
} }
return content this.callback(null, content, map)
} }
const path = require('path')
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const { const {
initAutoImportScanComponents initAutoImportScanComponents
} = require('@dcloudio/uni-cli-shared/lib/pages') } = require('@dcloudio/uni-cli-shared/lib/pages')
...@@ -11,19 +5,19 @@ const { ...@@ -11,19 +5,19 @@ const {
let compiling = false let compiling = false
class WebpackUniAppPlugin { class WebpackUniAppPlugin {
apply(compiler) { apply (compiler) {
if (process.UNI_CONFUSION) { if (process.UNI_CONFUSION) {
compiler.hooks.emit.tapPromise('webpack-uni-app-emit', compilation => { compiler.hooks.emit.tapPromise('webpack-uni-app-emit', compilation => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (compilation.assets['app-confusion.js']) { //存在加密 if (compilation.assets['app-confusion.js']) { // 存在加密
const manifestJson = JSON.parse(`${compilation.assets['manifest.json'].source()}`) const manifestJson = JSON.parse(`${compilation.assets['manifest.json'].source()}`)
manifestJson.plus.confusion.resources['app-confusion.js'] = {} manifestJson.plus.confusion.resources['app-confusion.js'] = {}
const source = JSON.stringify(manifestJson) const source = JSON.stringify(manifestJson)
compilation.assets['manifest.json'] = { compilation.assets['manifest.json'] = {
size() { size () {
return Buffer.byteLength(source, 'utf8') return Buffer.byteLength(source, 'utf8')
}, },
source() { source () {
return source return source
} }
} }
......
module.exports = function(source, map) { module.exports = function (source, map) {
/* eslint-disable no-mixed-operators */
console.warn( console.warn(
`App平台 v3 模式暂不支持在 js 文件中引用"${this._module && this._module.rawRequest || this.resourcePath}"` `App平台 v3 模式暂不支持在 js 文件中引用"${this._module && this._module.rawRequest || this.resourcePath}"`
) )
return '' this.callback(null, '', map)
} }
...@@ -8,7 +8,7 @@ const { ...@@ -8,7 +8,7 @@ const {
getUsingComponentsCode getUsingComponentsCode
} = require('@dcloudio/uni-cli-shared/lib/pages') } = require('@dcloudio/uni-cli-shared/lib/pages')
module.exports = function(content, map) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const resourcePath = removeExt( const resourcePath = removeExt(
normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)) normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
...@@ -16,7 +16,7 @@ module.exports = function(content, map) { ...@@ -16,7 +16,7 @@ module.exports = function(content, map) {
content = content + getUsingComponentsCode(resourcePath) content = content + getUsingComponentsCode(resourcePath)
// TODO 自动导入 vue 组件(h5,小程序,app[vue,nvue]) // TODO 自动导入 vue 组件(h5,小程序,app[vue,nvue])
// 1. 需要 template-loader 解析出所有自定义组件() // 1. 需要 template-loader 解析出所有自定义组件()
// 2. 根据自定义组件信息生成引用代码 // 2. 根据自定义组件信息生成引用代码
// 3. node-modules中的组件不提供自动导入 // 3. node-modules中的组件不提供自动导入
return content this.callback(null, content, map)
} }
...@@ -21,7 +21,7 @@ const { ...@@ -21,7 +21,7 @@ const {
parseComponents parseComponents
} = require('./util') } = require('./util')
function getDefineComponents({ function getDefineComponents ({
components components
}) { }) {
return components.map(({ return components.map(({
...@@ -32,7 +32,7 @@ function getDefineComponents({ ...@@ -32,7 +32,7 @@ function getDefineComponents({
const appVueFilePath = path.resolve(process.env.UNI_INPUT_DIR, 'app.vue') const appVueFilePath = path.resolve(process.env.UNI_INPUT_DIR, 'app.vue')
function getStylesCode(loaderContext) { function getStylesCode (loaderContext) {
if (!fs.existsSync(appVueFilePath)) { if (!fs.existsSync(appVueFilePath)) {
return return
} }
...@@ -59,10 +59,8 @@ function getStylesCode(loaderContext) { ...@@ -59,10 +59,8 @@ function getStylesCode(loaderContext) {
}) })
// styles // styles
let stylesCode = `` let stylesCode = ''
if (descriptor.styles.length) { if (descriptor.styles.length) {
const isServer = false
const isShadow = false
const isProduction = options.productionMode || minimize || process.env.NODE_ENV === 'production' const isProduction = options.productionMode || minimize || process.env.NODE_ENV === 'production'
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r) const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
...@@ -77,9 +75,9 @@ function getStylesCode(loaderContext) { ...@@ -77,9 +75,9 @@ function getStylesCode(loaderContext) {
const needsHotReload = false const needsHotReload = false
const id = hash( const id = hash(
isProduction ? isProduction
(shortFilePath + '\n' + source) : ? (shortFilePath + '\n' + source)
shortFilePath : shortFilePath
) )
stylesCode = genStylesCode( stylesCode = genStylesCode(
loaderContext, loaderContext,
...@@ -95,14 +93,15 @@ function getStylesCode(loaderContext) { ...@@ -95,14 +93,15 @@ function getStylesCode(loaderContext) {
return stylesCode.replace(/main\.[jt]s/g, 'App.vue') return stylesCode.replace(/main\.[jt]s/g, 'App.vue')
} }
module.exports = function(source, map) { module.exports = function (source, map) {
// 追加小程序全局自定义组件(仅v3) // 追加小程序全局自定义组件(仅v3)
source = getGlobalUsingComponentsCode() + source source = getGlobalUsingComponentsCode() + source
const automatorCode = process.env.UNI_AUTOMATOR_WS_ENDPOINT ? const automatorCode = process.env.UNI_AUTOMATOR_WS_ENDPOINT
`import '@dcloudio/uni-app-plus/dist/automator.view'` : ? 'import \'@dcloudio/uni-app-plus/dist/automator.view\''
'' : ''
return ` this.callback(null,
import 'uni-pages?${JSON.stringify({type:'view'})}' `
import 'uni-pages?${JSON.stringify({ type: 'view' })}'
${automatorCode} ${automatorCode}
function initView(){ function initView(){
${getStylesCode(this)} ${getStylesCode(this)}
...@@ -115,5 +114,6 @@ if(typeof plus !== 'undefined'){ ...@@ -115,5 +114,6 @@ if(typeof plus !== 'undefined'){
} else { } else {
document.addEventListener('plusready',initView) document.addEventListener('plusready',initView)
} }
` `,
map)
} }
const path = require('path') module.exports = function (source, map) {
const loaderUtils = require('loader-utils')
module.exports = function(source, map) {
const params = loaderUtils.parseQuery(this.resourceQuery)
// v3 app-plus // v3 app-plus
if (process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_USING_V3) { if (process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_USING_V3) {
this.callback( return this.callback(
null, null,
`export default function (Component) { `export default function (Component) {
${source.trim()} ${source.trim()}
...@@ -14,5 +9,5 @@ ${source.trim()} ...@@ -14,5 +9,5 @@ ${source.trim()}
map map
) )
} }
return source this.callback(null, source, map)
} }
...@@ -10,7 +10,7 @@ const { ...@@ -10,7 +10,7 @@ const {
parseComponents parseComponents
} = require('./util') } = require('./util')
function genComponentCode(components) { function genComponentCode (components) {
const importCode = [] const importCode = []
const componentsCode = [] const componentsCode = []
components.forEach(({ components.forEach(({
...@@ -24,7 +24,7 @@ function genComponentCode(components) { ...@@ -24,7 +24,7 @@ function genComponentCode(components) {
return [importCode.join('\n'), componentsCode.join(',\n')] return [importCode.join('\n'), componentsCode.join(',\n')]
} }
function genCode({ function genCode ({
components, components,
options options
}, css = []) { }, css = []) {
...@@ -37,10 +37,10 @@ function genCode({ ...@@ -37,10 +37,10 @@ function genCode({
return ` return `
${importComponentCode} ${importComponentCode}
export default { export default {
${optionsCode.length?(optionsCode.join(',')+','):''} ${optionsCode.length ? (optionsCode.join(',') + ',') : ''}
data(){ data(){
return { return {
wxsProps:{} wxsProps:{}
} }
}, },
components:{ components:{
...@@ -50,12 +50,12 @@ export default { ...@@ -50,12 +50,12 @@ export default {
` `
} }
module.exports = function(content, map) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
content = preprocessor.preprocess(content, jsPreprocessOptions.context, { content = preprocessor.preprocess(content, jsPreprocessOptions.context, {
type: jsPreprocessOptions.type type: jsPreprocessOptions.type
}) })
return genCode(parseComponents(content, traverse)) this.callback(null, genCode(parseComponents(content, traverse)), map)
} }
...@@ -5,20 +5,19 @@ const isWin = /^win/.test(process.platform) ...@@ -5,20 +5,19 @@ const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const AppPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'App.vue')) const AppPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'App.vue'))
module.exports = function(content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
if (this.resourceQuery) { if (this.resourceQuery) {
const params = loaderUtils.parseQuery(this.resourceQuery) const params = loaderUtils.parseQuery(this.resourceQuery)
if (params.mpType === 'page') { if (params.mpType === 'page') {
return content return this.callback(null, content, map)
} }
} }
if (normalizePath(this.resourcePath) === AppPath) { if (normalizePath(this.resourcePath) === AppPath) {
return content return this.callback(null, content, map)
} }
if (content.indexOf('platform="mp-weixin"') !== -1) { if (content.indexOf('platform="mp-weixin"') !== -1) {
return content return this.callback(null, content, map)
} }
return content.replace(/(<style\b[^><]*)>/ig, '$1 scoped>') return this.callback(null, content.replace(/(<style\b[^><]*)>/ig, '$1 scoped>'), map)
} }
const parser = require('@babel/parser') const parser = require('@babel/parser')
function parseComponents(content, traverse) { function parseComponents (content, traverse) {
const { const {
state: { state: {
options, options,
......
...@@ -10,7 +10,7 @@ const { ...@@ -10,7 +10,7 @@ const {
normalizeNodeModules normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform') } = require('@dcloudio/uni-cli-shared/lib/platform')
module.exports = function(source, map) { module.exports = function (source, map) {
const params = loaderUtils.parseQuery(this.resourceQuery) const params = loaderUtils.parseQuery(this.resourceQuery)
if ( if (
process.env.UNI_PLATFORM === 'h5' || process.env.UNI_PLATFORM === 'h5' ||
...@@ -35,7 +35,7 @@ module.exports = function(source, map) { ...@@ -35,7 +35,7 @@ module.exports = function(source, map) {
traverse(parser.parse(source, { traverse(parser.parse(source, {
sourceType: 'module' sourceType: 'module'
}), { }), {
MemberExpression(path, state) { MemberExpression (path, state) {
const property = path.node.property const property = path.node.property
const parentNode = path.parent const parentNode = path.parent
if ( if (
...@@ -60,8 +60,8 @@ module.exports = function(source, map) { ...@@ -60,8 +60,8 @@ module.exports = function(source, map) {
if(!Component.options.wxsCallMethods){ if(!Component.options.wxsCallMethods){
Component.options.wxsCallMethods = [] Component.options.wxsCallMethods = []
} }
${[...callMethods].map(method=>{ ${[...callMethods].map(method => {
return "Component.options.wxsCallMethods.push('"+method+"')" return "Component.options.wxsCallMethods.push('" + method + "')"
}).join('\n')} }).join('\n')}
}`, }`,
map) map)
......
const utils = require('loader-utils') const utils = require('loader-utils')
module.exports = function (source) { module.exports = function (source, map) {
this.cacheable() this.cacheable()
const opts = utils.getOptions(this) || {} const opts = utils.getOptions(this) || {}
// fixed by xxxxxx 保持行号不变 this.callback(null, [].concat(opts.before, source, opts.after).join('').trim(), map)
return [].concat(opts.before, source, opts.after).join('').trim()
// return [].concat(opts.before, source, opts.after).join('\n').trim()
} }
...@@ -45,7 +45,7 @@ function addCreateApp (babelLoader) { ...@@ -45,7 +45,7 @@ function addCreateApp (babelLoader) {
babelLoader.options.plugins.push([babelPluginCreateApp]) babelLoader.options.plugins.push([babelPluginCreateApp])
} }
module.exports = function (content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
if (this.resourceQuery) { if (this.resourceQuery) {
...@@ -65,11 +65,12 @@ module.exports = function (content) { ...@@ -65,11 +65,12 @@ module.exports = function (content) {
} }
} }
} }
return ` return this.callback(null,
`
import Vue from 'vue' import Vue from 'vue'
import Page from './${normalizePath(params.page)}${ext}' import Page from './${normalizePath(params.page)}${ext}'
createPage(Page) createPage(Page)
` `, map)
} }
} else { } else {
content = preprocessor.preprocess(content, jsPreprocessOptions.context, { content = preprocessor.preprocess(content, jsPreprocessOptions.context, {
...@@ -96,7 +97,7 @@ createPage(Page) ...@@ -96,7 +97,7 @@ createPage(Page)
if (!components.length) { if (!components.length) {
// 防止组件从有到无 // 防止组件从有到无
updateUsingComponents(resourcePath, Object.create(null), 'App') updateUsingComponents(resourcePath, Object.create(null), 'App')
return content return this.callback(null, content, map)
} }
const callback = this.async() const callback = this.async()
...@@ -130,9 +131,9 @@ createPage(Page) ...@@ -130,9 +131,9 @@ createPage(Page)
addDynamicImport(babelLoader, resourcePath, dynamicImports) addDynamicImport(babelLoader, resourcePath, dynamicImports)
updateUsingComponents(resourcePath, usingComponents, 'App') updateUsingComponents(resourcePath, usingComponents, 'App')
callback(null, content) callback(null, content, map)
}, err => { }, err => {
callback(err, content) callback(err, content, map)
}) })
} }
} }
...@@ -36,9 +36,9 @@ function getMPVuePageFactoryMainJsCode (params) { ...@@ -36,9 +36,9 @@ function getMPVuePageFactoryMainJsCode (params) {
Page(pageFactory(App))` Page(pageFactory(App))`
} }
module.exports = function (content) { module.exports = function (content, map) {
if (process.env.UNI_USING_COMPONENTS) { if (process.env.UNI_USING_COMPONENTS) {
return require('./main-new').call(this, content) return require('./main-new').call(this, content, map)
} }
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
if (this.resourceQuery) { if (this.resourceQuery) {
......
...@@ -19,7 +19,7 @@ module.exports = function (content, map) { ...@@ -19,7 +19,7 @@ module.exports = function (content, map) {
if (process.env.UNI_PLATFORM === 'app-plus') { if (process.env.UNI_PLATFORM === 'app-plus') {
return require('./script-new').call(this, content, map) return require('./script-new').call(this, content, map)
} }
return require('./script-new').call(this, content) return require('./script-new').call(this, content, map)
} }
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
......
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const { const {
removeExt, removeExt,
normalizePath, normalizePath,
getFlexDirection, getFlexDirection,
parseManifestJson parseManifestJson
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
...@@ -12,14 +12,14 @@ const { ...@@ -12,14 +12,14 @@ const {
normalizeNodeModules normalizeNodeModules
} = require('./shared') } = require('./shared')
module.exports = function (content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
if (!process.env.UNI_USING_NVUE_COMPILER) { if (!process.env.UNI_USING_NVUE_COMPILER) {
return content return this.callback(null, content, map)
} }
if (path.extname(this.resourcePath) !== '.nvue') { if (path.extname(this.resourcePath) !== '.nvue') {
return content return this.callback(null, content, map)
} }
const resourcePath = normalizeNodeModules( const resourcePath = normalizeNodeModules(
removeExt( removeExt(
...@@ -27,22 +27,24 @@ module.exports = function (content) { ...@@ -27,22 +27,24 @@ module.exports = function (content) {
) )
) )
if (!process.UNI_ENTRY[resourcePath]) { if (!process.UNI_ENTRY[resourcePath]) {
return content return this.callback(null, content, map)
} }
const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json') const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json')
const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, 'utf8')) const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, 'utf8'))
return `<style> this.callback(null,
`${content}
<style>
view, view,
swiper-item, swiper-item,
scroll-view { scroll-view {
display:flex; display:flex;
flex-direction:${getFlexDirection(manifestJson['app-plus'])}; flex-direction:${getFlexDirection(manifestJson['app-plus'])};
flex-shrink: 0; flex-shrink: 0;
flex-grow: 0; flex-grow: 0;
flex-basis: auto; flex-basis: auto;
align-items: stretch; align-items: stretch;
align-content: flex-start; align-content: flex-start;
} }
view, view,
...@@ -57,10 +59,10 @@ module.exports = function (content) { ...@@ -57,10 +59,10 @@ module.exports = function (content) {
position: relative; position: relative;
border: 0px solid #000000; border: 0px solid #000000;
box-sizing: border-box; box-sizing: border-box;
}
swiper-item {
position: absolute;
} }
</style> swiper-item {
${content}` position: absolute;
}
</style>`,
map)
} }
...@@ -28,15 +28,15 @@ const { ...@@ -28,15 +28,15 @@ const {
const templateExt = getPlatformExts().template const templateExt = getPlatformExts().template
const filterTagName = getPlatformFilterTag() || '' const filterTagName = getPlatformFilterTag() || ''
function parseFilterModules (filterModules) { function parseFilterModules (filterModules) {
if (filterModules) { if (filterModules) {
return JSON.parse(Buffer.from(filterModules, 'base64').toString('utf8')) return JSON.parse(Buffer.from(filterModules, 'base64').toString('utf8'))
} }
return {} return {}
} }
module.exports = function (content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options') const vueLoaderOptions = this.loaders.find(loader => loader.ident === 'vue-loader-options')
...@@ -69,5 +69,5 @@ module.exports = function (content) { ...@@ -69,5 +69,5 @@ module.exports = function (content) {
} else { } else {
throw new Error('vue-loader-options parse error') throw new Error('vue-loader-options parse error')
} }
return content this.callback(null, content, map)
} }
...@@ -32,7 +32,7 @@ function renameUsingComponents (jsonObj) { ...@@ -32,7 +32,7 @@ function renameUsingComponents (jsonObj) {
return jsonObj return jsonObj
} }
module.exports = function (content) { module.exports = function (content, map) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
let isAppView = false let isAppView = false
...@@ -67,10 +67,10 @@ module.exports = function (content) { ...@@ -67,10 +67,10 @@ module.exports = function (content) {
} }
if (process.env.UNI_PLATFORM === 'h5') { if (process.env.UNI_PLATFORM === 'h5') {
return require('./platforms/h5')(pagesJson, manifestJson, this) return this.callback(null, require('./platforms/h5')(pagesJson, manifestJson, this), map)
} }
if (process.env.UNI_PLATFORM === 'quickapp-native') { if (process.env.UNI_PLATFORM === 'quickapp-native') {
return require('./platforms/quickapp-native')(pagesJson, manifestJson, this) return this.callback(null, require('./platforms/quickapp-native')(pagesJson, manifestJson, this), map)
} }
if (!process.env.UNI_USING_V3) { if (!process.env.UNI_USING_V3) {
...@@ -104,7 +104,7 @@ module.exports = function (content) { ...@@ -104,7 +104,7 @@ module.exports = function (content) {
} }
} }
}) })
return appConfigContent return this.callback(null, appConfigContent, map)
} }
if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
let appConfigContent = '' let appConfigContent = ''
...@@ -117,7 +117,7 @@ module.exports = function (content) { ...@@ -117,7 +117,7 @@ module.exports = function (content) {
} }
} }
}) })
return appConfigContent return this.callback(null, appConfigContent, map)
} }
jsonFiles.forEach(jsonFile => { jsonFiles.forEach(jsonFile => {
...@@ -131,5 +131,5 @@ module.exports = function (content) { ...@@ -131,5 +131,5 @@ module.exports = function (content) {
}) })
} }
return '' this.callback(null, '', map)
} }
...@@ -29,7 +29,7 @@ function checkEmitFile (filePath, jsonObj, changedEmitFiles) { ...@@ -29,7 +29,7 @@ function checkEmitFile (filePath, jsonObj, changedEmitFiles) {
} }
} }
module.exports = function (content) { module.exports = function (content, map) {
if (this.resourceQuery) { if (this.resourceQuery) {
const params = loaderUtils.parseQuery(this.resourceQuery) const params = loaderUtils.parseQuery(this.resourceQuery)
if (params) { if (params) {
...@@ -46,7 +46,7 @@ module.exports = function (content) { ...@@ -46,7 +46,7 @@ module.exports = function (content) {
process.env.UNI_PLATFORM === 'h5' || process.env.UNI_PLATFORM === 'h5' ||
process.env.UNI_PLATFORM === 'quickapp-native' process.env.UNI_PLATFORM === 'quickapp-native'
) { ) {
return require('./index-new').call(this, content) return require('./index-new').call(this, content, map)
} }
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
...@@ -98,5 +98,5 @@ module.exports = function (content) { ...@@ -98,5 +98,5 @@ module.exports = function (content) {
this.emitFile(name + '.json', emitFileCaches[name]) this.emitFile(name + '.json', emitFileCaches[name])
}) })
return '' this.callback(null, '', map)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册