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

feat(v3): subPackages

上级 a199e2d9
...@@ -4,13 +4,12 @@ const { ...@@ -4,13 +4,12 @@ const {
normalizePath normalizePath
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
function createCacheGroups () { function createCacheGroups() {
const cacheGroups = {} const cacheGroups = {}
if (process.UNI_CONFUSION) { // 加密 if (process.UNI_CONFUSION) { // 加密
cacheGroups.confusion = { cacheGroups.confusion = {
minSize: 0, enforce: true,
minChunks: 1, test: function(module) {
test: function (module) {
if (!module.resource) { if (!module.resource) {
return false return false
} }
...@@ -26,9 +25,8 @@ function createCacheGroups () { ...@@ -26,9 +25,8 @@ function createCacheGroups () {
process.env.UNI_OPT_SUBPACKAGES && Object.keys(process.UNI_SUBPACKAGES).forEach(root => { process.env.UNI_OPT_SUBPACKAGES && Object.keys(process.UNI_SUBPACKAGES).forEach(root => {
cacheGroups[root] = { cacheGroups[root] = {
minSize: 0, enforce: true,
minChunks: 1, test: function(module) {
test: function (module) {
if (!module.resource) { if (!module.resource) {
return false return false
} }
...@@ -44,7 +42,7 @@ function createCacheGroups () { ...@@ -44,7 +42,7 @@ function createCacheGroups () {
return cacheGroups return cacheGroups
} }
module.exports = function getSplitChunks () { module.exports = function getSplitChunks() {
const { const {
normalizePath normalizePath
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
...@@ -71,14 +69,14 @@ module.exports = function getSplitChunks () { ...@@ -71,14 +69,14 @@ module.exports = function getSplitChunks () {
if (!process.env.UNI_OPT_SUBPACKAGES) { if (!process.env.UNI_OPT_SUBPACKAGES) {
return { return {
chunks (chunk) { // 防止 node_modules 内 vue 组件被 split chunks(chunk) { // 防止 node_modules 内 vue 组件被 split
return chunk.name.indexOf('node-modules') !== 0 return chunk.name.indexOf('node-modules') !== 0
}, },
cacheGroups: { cacheGroups: {
default: false, default: false,
vendors: false, vendors: false,
commons: { commons: {
test (module) { test(module) {
if (module.type === 'css/mini-extract') { if (module.type === 'css/mini-extract') {
return false return false
} }
...@@ -99,7 +97,7 @@ module.exports = function getSplitChunks () { ...@@ -99,7 +97,7 @@ module.exports = function getSplitChunks () {
} }
} }
function baseTest (module) { function baseTest(module) {
if (module.type === 'css/mini-extract') { if (module.type === 'css/mini-extract') {
return false return false
} }
...@@ -121,7 +119,7 @@ module.exports = function getSplitChunks () { ...@@ -121,7 +119,7 @@ module.exports = function getSplitChunks () {
default: false, default: false,
vendors: false, vendors: false,
commons: { commons: {
test (module, chunks) { test(module, chunks) {
if (!baseTest(module)) { if (!baseTest(module)) {
return false return false
} }
...@@ -146,7 +144,7 @@ module.exports = function getSplitChunks () { ...@@ -146,7 +144,7 @@ module.exports = function getSplitChunks () {
} }
} }
const findSubPackages = function (chunks) { const findSubPackages = function(chunks) {
return chunks.reduce((pkgs, item) => { return chunks.reduce((pkgs, item) => {
const name = normalizePath(item.name) const name = normalizePath(item.name)
const pkgRoot = subPackageRoots.find(root => name.indexOf(root) === 0) const pkgRoot = subPackageRoots.find(root => name.indexOf(root) === 0)
...@@ -155,16 +153,16 @@ module.exports = function getSplitChunks () { ...@@ -155,16 +153,16 @@ module.exports = function getSplitChunks () {
}, new Set()) }, new Set())
} }
const hasMainPackage = function (chunks) { const hasMainPackage = function(chunks) {
return chunks.find(item => !subPackageRoots.find(root => item.name.indexOf(root) === 0)) return chunks.find(item => !subPackageRoots.find(root => item.name.indexOf(root) === 0))
} }
const subPackageRoots = Object.keys(process.UNI_SUBPACKAGES).map(root => root + '/') const subPackageRoots = Object.keys(process.UNI_SUBPACKAGES).map(root => root + '/')
Object.keys(process.UNI_SUBPACKAGES).forEach(root => { Object.keys(process.UNI_SUBPACKAGES).forEach(root => {
(function (root) { (function(root) {
cacheGroups[root + '/commons'] = { cacheGroups[root + '/commons'] = {
test (module, chunks) { test(module, chunks) {
if (!baseTest(module)) { if (!baseTest(module)) {
return false return false
} }
...@@ -189,7 +187,7 @@ module.exports = function getSplitChunks () { ...@@ -189,7 +187,7 @@ module.exports = function getSplitChunks () {
}) })
return { return {
chunks (chunk) { // 防止 node_modules 内 vue 组件被 split chunks(chunk) { // 防止 node_modules 内 vue 组件被 split
return chunk.name.indexOf('node-modules') !== 0 return chunk.name.indexOf('node-modules') !== 0
}, },
cacheGroups cacheGroups
......
...@@ -5,9 +5,8 @@ import { ...@@ -5,9 +5,8 @@ import {
const SUB_FILENAME = 'app-sub-service.js' const SUB_FILENAME = 'app-sub-service.js'
function evaluateScriptFile (file, callback) { function evaluateScriptFile (file, callback) {
setTimeout(() => { // TODO 有可能当前 instance 是非 app-service
callback() weex.requireModule('plus').evalJSFiles([file], callback)
}, 2000)
} }
export function loadSubPackage ({ export function loadSubPackage ({
......
...@@ -63,9 +63,8 @@ function loadSubPackage (root, callback) { ...@@ -63,9 +63,8 @@ function loadSubPackage (root, callback) {
const SUB_FILENAME = 'app-sub-service.js' const SUB_FILENAME = 'app-sub-service.js'
function evaluateScriptFiles (files, callback) { function evaluateScriptFiles (files, callback) {
setTimeout(() => { // TODO 有可能当前 instance 是非 app-service
callback() weex.requireModule('plus').evalJSFiles(files, callback)
}, 2000)
} }
function loadSubPackages (packages, callback) { function loadSubPackages (packages, callback) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册