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

feat(v3): Add scoped attribute to style tag for custom components

上级 12eebdea
......@@ -236,6 +236,14 @@ const v3 = {
}
if (isAppView) {
if (process.env.UNI_USING_V3_SCOPED) {
webpackConfig.module
.rule('vue')
.use('uniapp-app-style-scoped')
.loader(path.resolve(__dirname,
'../../packages/webpack-uni-app-loader/view/style'))
}
if (process.env.NODE_ENV === 'production') {
require('../h5/cssnano-options')(webpackConfig)
}
......
......@@ -25,6 +25,8 @@ global.uniPlugin.validate.forEach(validate => {
})
process.UNI_MANIFEST = manifestJsonObj
process.env.UNI_USING_V3_SCOPED = true
process.UNI_CLOUD = false
process.UNI_CLOUD_TCB = false
......
const path = require('path')
const loaderUtils = require('loader-utils')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const AppPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'App.vue'))
module.exports = function(content) {
this.cacheable && this.cacheable()
if (this.resourceQuery) {
const params = loaderUtils.parseQuery(this.resourceQuery)
if (params.mpType === 'page') {
return content
}
}
if (normalizePath(this.resourcePath) === AppPath) {
return content
}
if (content.indexOf('platform="mp-weixin"') !== -1) {
return content
}
return content.replace(/(<style\b[^><]*)>/ig, '$1 scoped>')
}
......@@ -3,7 +3,7 @@ function generatePageCode (pages, pageOptions) {
if (pageOptions[pagePath].nvue) {
return ''
}
return `__definePage('${pagePath}',function(){return Vue.extend(require('${pagePath}.vue').default)})`
return `__definePage('${pagePath}',function(){return Vue.extend(require('${pagePath}.vue?mpType=page').default)})`
}).join('\n')
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册