@mpxjs/webpack-plugin 2.7.0-beta.8 → 2.7.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ class DynamicEntryDependency extends NullDependency {
21
21
 
22
22
  get key () {
23
23
  const { resource, entryType, outputPath, packageRoot, relativePath, range } = this
24
- return [resource, entryType, outputPath, packageRoot, relativePath, ...range].join('|')
24
+ return toPosix([resource, entryType, outputPath, packageRoot, relativePath, ...range].join('|'))
25
25
  }
26
26
 
27
27
  addEntry (compilation, callback) {
package/lib/index.js CHANGED
@@ -80,6 +80,11 @@ const isChunkInPackage = (chunkName, packageName) => {
80
80
  const getPackageCacheGroup = packageName => {
81
81
  if (packageName === 'main') {
82
82
  return {
83
+ // 对于独立分包模块不应用该cacheGroup
84
+ test: (module) => {
85
+ const { queryObj } = parseRequest(module.resource)
86
+ return !queryObj.isIndependent
87
+ },
83
88
  name: 'bundle',
84
89
  minChunks: 2,
85
90
  chunks: 'all'
@@ -691,10 +696,12 @@ class MpxWebpackPlugin {
691
696
  compilation.errors.push(e)
692
697
  }
693
698
  })
694
- if (packageRoot) {
695
- module.request = addQuery(module.request, { packageRoot })
696
- module.resource = addQuery(module.resource, { packageRoot })
697
- }
699
+ const queryObj = {}
700
+ if (packageRoot) queryObj.packageRoot = packageRoot
701
+ // todo 后续可以考虑用module.layer来隔离独立分包的模块
702
+ if (isIndependent) queryObj.isIndependent = true
703
+ module.request = addQuery(module.request, queryObj)
704
+ module.resource = addQuery(module.resource, queryObj)
698
705
  }
699
706
  }
700
707
 
package/lib/loader.js CHANGED
@@ -217,14 +217,16 @@ module.exports = function (content) {
217
217
  if (!isProduction) {
218
218
  output += `global.currentResource = ${JSON.stringify(filePath)}\n`
219
219
  }
220
- if (ctorType === 'app' && i18n) {
221
- output += `global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}\n`
222
-
220
+ // app或独立分包页面注入i18n
221
+ if (i18n && (ctorType === 'app' || (ctorType === 'page' && queryObj.isIndependent))) {
223
222
  const i18nWxsPath = normalize.lib('runtime/i18n.wxs')
224
223
  const i18nWxsLoaderPath = normalize.lib('wxs/i18n-loader.js')
225
224
  const i18nWxsRequest = i18nWxsLoaderPath + '!' + i18nWxsPath
226
225
 
227
- output += `global.i18nMethods = require(${loaderUtils.stringifyRequest(loaderContext, i18nWxsRequest)})\n`
226
+ output += `if (!global.i18n) {
227
+ global.i18n = ${JSON.stringify({ locale: i18n.locale, version: 0 })}
228
+ global.i18nMethods = require(${loaderUtils.stringifyRequest(loaderContext, i18nWxsRequest)})
229
+ }\n`
228
230
  }
229
231
  // 注入构造函数
230
232
  let ctor = 'App'
@@ -303,6 +305,7 @@ module.exports = function (content) {
303
305
  if (script.src) extraOptions.resourcePath = resourcePath
304
306
  output += getRequire('script', script, extraOptions) + '\n'
305
307
  } else {
308
+ // todo 依然创建request在selector中进行补全或者将i18n通过CommonJsVariableDependency改造为initFragments的方式进行注入,否则在app.mpx中没有script区块的情况下无法保证i18n注入代码在@mpxjs/core之前执行
306
309
  switch (ctorType) {
307
310
  case 'app':
308
311
  output += 'import {createApp} from "@mpxjs/core"\n' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.0-beta.8",
3
+ "version": "2.7.0-beta.9",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -77,5 +77,5 @@
77
77
  "@types/babel-traverse": "^6.25.4",
78
78
  "@types/babel-types": "^7.0.4"
79
79
  },
80
- "gitHead": "73247d266ae7380b88295208d645f85b9dd72398"
80
+ "gitHead": "368e40835a53b627170f59e8fbe827b457bb2654"
81
81
  }