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

feat(v3): app-confusion.js

上级 a888a512
...@@ -73,12 +73,12 @@ const v3 = { ...@@ -73,12 +73,12 @@ const v3 = {
webpackConfig.optimization.runtimeChunk = { webpackConfig.optimization.runtimeChunk = {
name: 'app-config' name: 'app-config'
} }
webpackConfig.optimization.splitChunks = require('../split-chunks')()
} else if (isAppView) { } else if (isAppView) {
webpackConfig.optimization.runtimeChunk = false webpackConfig.optimization.runtimeChunk = false
webpackConfig.optimization.splitChunks = false
} }
webpackConfig.optimization.splitChunks = false
let devtool = false let devtool = false
if (isAppService && process.env.NODE_ENV !== 'production') { if (isAppService && process.env.NODE_ENV !== 'production') {
......
...@@ -14,7 +14,7 @@ if (process.env.UNI_CLOUD_SPACES) { ...@@ -14,7 +14,7 @@ if (process.env.UNI_CLOUD_SPACES) {
process.UNI_CLOUD = spaces.length > 0 process.UNI_CLOUD = spaces.length > 0
process.UNI_CLOUD_ALIYUN = !!spaces.find(space => space.clientSecret) process.UNI_CLOUD_ALIYUN = !!spaces.find(space => space.clientSecret)
if (spaces.length === 1) { if (spaces.length === 1) {
const space = spaces[0] const space = spaces[0]
console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`) console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`)
if (space.clientSecret) { if (space.clientSecret) {
process.env.UNI_CLOUD_PROVIDER = JSON.stringify({ process.env.UNI_CLOUD_PROVIDER = JSON.stringify({
...@@ -85,7 +85,8 @@ if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache ...@@ -85,7 +85,8 @@ if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache
delete process.env.UNI_USING_CACHE delete process.env.UNI_USING_CACHE
} }
const { const {
normalizePath,
isSupportSubPackages, isSupportSubPackages,
runByHBuilderX, runByHBuilderX,
// isInHBuilderXAlpha, // isInHBuilderXAlpha,
...@@ -194,6 +195,21 @@ if (process.env.UNI_PLATFORM === 'app-plus') { ...@@ -194,6 +195,21 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
process.env.UNI_USING_V8 = true process.env.UNI_USING_V8 = true
process.env.UNI_OUTPUT_TMP_DIR = '' process.env.UNI_OUTPUT_TMP_DIR = ''
} }
// v3 支持指定 js 混淆(仅发行模式)
if (
process.env.NODE_ENV === 'production' &&
process.env.UNI_USING_V3
) {
const resources = platformOptions.confusion &&
platformOptions.confusion.resources
const resourcesKeys = resources &&
Object.keys(resources).filter(filepath => path.extname(filepath) === '.js')
if (resourcesKeys && resourcesKeys.length) {
process.UNI_CONFUSION = resourcesKeys.map(filepath =>
normalizePath(path.resolve(process.env.UNI_INPUT_DIR, filepath))
)
}
}
} else { // 其他平台,待确认配置方案 } else { // 其他平台,待确认配置方案
if ( if (
manifestJsonObj['app-plus'] && manifestJsonObj['app-plus'] &&
......
const path = require('path') const path = require('path')
module.exports = function getSplitChunks () { module.exports = function getSplitChunks () {
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
if (process.env.UNI_USING_V3) { if (process.env.UNI_USING_V3) {
return false if (!process.UNI_CONFUSION) { // 无加密
return false
}
return {
cacheGroups: {
vendor: {
minSize: 0,
minChunks: 1,
test: function (module) {
if (!module.resource) {
return false
}
if (process.UNI_CONFUSION.includes(normalizePath(module.resource))) {
return true
}
return false
},
name: 'app-confusion',
chunks: 'all'
}
}
}
} }
if (!process.env.UNI_USING_COMPONENTS) { if (!process.env.UNI_USING_COMPONENTS) {
return { return {
...@@ -16,10 +41,6 @@ module.exports = function getSplitChunks () { ...@@ -16,10 +41,6 @@ module.exports = function getSplitChunks () {
} }
} }
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const mainPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'main.')) const mainPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'main.'))
if (!process.env.UNI_OPT_SUBPACKAGES) { if (!process.env.UNI_OPT_SUBPACKAGES) {
......
...@@ -321,15 +321,19 @@ module.exports = function (pagesJson, userManifestJson) { ...@@ -321,15 +321,19 @@ module.exports = function (pagesJson, userManifestJson) {
// 检查原生混淆选项 // 检查原生混淆选项
const confusion = manifestJson.plus.confusion const confusion = manifestJson.plus.confusion
if (confusion && confusion.resources) { if (confusion && confusion.resources) {
const resources = {} const resources = {}
const nvuePages = (appJson.nvue && appJson.nvue.pages) || {}
for (const key in confusion.resources) { for (const key in confusion.resources) {
if (path.extname(key) === '.js') { // 支持 js 混淆,过滤掉
continue
}
if (!/\.nvue$/.test(key)) { if (!/\.nvue$/.test(key)) {
throw new Error(`原生混淆仅支持 nvue 页面,错误的页面路径:${key}`) throw new Error(`原生混淆仅支持 nvue 页面,错误的页面路径:${key}`)
} else { } else {
resources[key.replace(/\.nvue$/, '.js')] = confusion.resources[key] resources[key.replace(/\.nvue$/, '.js')] = confusion.resources[key]
} }
if (!Object.keys(appJson.nvue.pages).find(path => { if (!Object.keys(nvuePages).find(path => {
const subNVues = appJson.nvue.pages[path].window.subNVues || [] const subNVues = nvuePages[path].window.subNVues || []
return path.replace(/\.html$/, '.nvue') === key || subNVues.find(({ return path.replace(/\.html$/, '.nvue') === key || subNVues.find(({
path path
}) => path === key.replace(/\.nvue$/, '')) }) => path === key.replace(/\.nvue$/, ''))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册