@dcloudio/vue-cli-plugin-uni 2.0.2-3061520221228002 → 2.0.2-3061720230112002

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.
package/lib/mp/index.js CHANGED
@@ -9,7 +9,9 @@ const {
9
9
  getPlatformCssnano,
10
10
  getPlatformStat,
11
11
  getPlatformPush,
12
- getPlatformUniCloud
12
+ getPlatformUniCloud,
13
+ createSource,
14
+ deleteAsset
13
15
  } = require('@dcloudio/uni-cli-shared')
14
16
 
15
17
  const WebpackUniAppPlugin = require('../../packages/webpack-uni-app-loader/plugin/index')
@@ -26,7 +28,7 @@ function createUniMPPlugin () {
26
28
  }
27
29
 
28
30
  const createWxMpIndependentPlugins = require('@dcloudio/uni-mp-weixin/lib/createIndependentPlugin')
29
-
31
+
30
32
  const UniTips = require('./tips')
31
33
 
32
34
  function getProvides () {
@@ -74,65 +76,67 @@ function getProvides () {
74
76
  ) { // 非微信小程序,自动注入 wx 对象
75
77
  provides.wx = provides.uni
76
78
  }
79
+ if (process.env.UNI_PLATFORM === 'mp-weixin') {
80
+ provides.wx = [path.resolve(uniPath, '../wx.js'), 'default']
81
+ }
77
82
  return provides
78
83
  }
79
84
 
80
- function processWxss (name, assets) {
85
+ function processWxss (compilation, name, assets) {
81
86
  const dirname = path.dirname(name)
82
87
  const mainWxssCode = `@import "${normalizePath(path.relative(dirname, 'common/main.wxss'))}";`
83
88
  const code = `${mainWxssCode}` + assets[name].source().toString()
84
- assets[name] = {
85
- size () {
86
- return Buffer.byteLength(code, 'utf8')
87
- },
88
- source () {
89
- return code
90
- }
91
- }
89
+ compilation.updateAsset(name, createSource(code))
92
90
  }
93
91
 
94
92
  const parseRequirePath = path => path.startsWith('common') ? `./${path}` : path
95
93
 
96
- function procssJs (name, assets, hasVendor) {
94
+ function procssJs (compilation, name, assets, hasVendor) {
97
95
  const dirname = path.dirname(name)
98
96
  const runtimeJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/runtime.js')))}');`
99
97
  const vendorJsCode = hasVendor
100
98
  ? `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/vendor.js')))}');` : ''
101
99
  const mainJsCode = `require('${normalizePath(parseRequirePath(path.relative(dirname, 'common/main.js')))}');`
102
100
  const code = `${runtimeJsCode}${vendorJsCode}${mainJsCode}` + assets[name].source().toString()
103
- assets[name] = {
104
- size () {
105
- return Buffer.byteLength(code, 'utf8')
106
- },
107
- source () {
108
- return code
101
+ compilation.updateAsset(name, createSource(code))
102
+ }
103
+
104
+ function processAssets (compilation) {
105
+ const assets = compilation.assets
106
+ const hasMainWxss = assets['common/main.wxss']
107
+ const hasVendor = assets['common/vendor.js']
108
+ Object.keys(assets).forEach(name => {
109
+ if (name.startsWith('common')) {
110
+ return
109
111
  }
110
- }
112
+ const extname = path.extname(name)
113
+ if (extname === '.wxss' && hasMainWxss && process.UNI_ENTRY[name.replace(extname, '')]) {
114
+ processWxss(compilation, name, assets)
115
+ } else if (extname === '.js') {
116
+ procssJs(compilation, name, assets, hasVendor)
117
+ }
118
+ })
119
+ // delete assets['common/main.js']
120
+ deleteAsset(compilation, 'app.js')
121
+ deleteAsset(compilation, 'app.json')
122
+ deleteAsset(compilation, 'app.wxss')
123
+ deleteAsset(compilation, 'project.config.json')
111
124
  }
112
125
 
113
126
  class PreprocessAssetsPlugin {
114
127
  apply (compiler) {
115
- compiler.hooks.emit.tap('PreprocessAssetsPlugin', compilation => {
116
- const assets = compilation.assets
117
- const hasMainWxss = assets['common/main.wxss']
118
- const hasVendor = assets['common/vendor.js']
119
- Object.keys(assets).forEach(name => {
120
- if (name.startsWith('common')) {
121
- return
122
- }
123
- const extname = path.extname(name)
124
- if (extname === '.wxss' && hasMainWxss && process.UNI_ENTRY[name.replace(extname, '')]) {
125
- processWxss(name, assets)
126
- } else if (extname === '.js') {
127
- procssJs(name, assets, hasVendor)
128
- }
128
+ if (webpack.version[0] > 4) {
129
+ compiler.hooks.compilation.tap('PreprocessAssetsPlugin', compilation => {
130
+ compilation.hooks.processAssets.tap({
131
+ name: 'PreprocessAssetsPlugin',
132
+ stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
133
+ }, (_) => {
134
+ processAssets(compilation)
135
+ })
129
136
  })
130
- // delete assets['common/main.js']
131
- delete assets['app.js']
132
- delete assets['app.json']
133
- delete assets['app.wxss']
134
- delete assets['project.config.json']
135
- })
137
+ } else {
138
+ compiler.hooks.emit.tap('PreprocessAssetsPlugin', (compilation) => processAssets(compilation))
139
+ }
136
140
  }
137
141
  }
138
142
 
@@ -143,7 +147,8 @@ function initSubpackageConfig (webpackConfig, vueOptions) {
143
147
  }
144
148
  vueOptions.outputDir = process.env.UNI_OUTPUT_DIR
145
149
  webpackConfig.output.path(process.env.UNI_OUTPUT_DIR)
146
- webpackConfig.output.jsonpFunction('webpackJsonp_' + (process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN))
150
+ webpackConfig.output.set(webpack.version[0] > 4 ? 'chunkLoadingGlobal' : 'jsonpFunction', 'webpackJsonp_' + (process
151
+ .env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN))
147
152
  }
148
153
 
149
154
  function addToUniEntry (fileName) {
@@ -192,7 +197,7 @@ module.exports = {
192
197
 
193
198
  if ((process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) && process.env.UNI_SUBPACKGE !== 'main') {
194
199
  plugins.push(new PreprocessAssetsPlugin())
195
- }
200
+ }
196
201
 
197
202
  {
198
203
  const globalEnv = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'wx';
@@ -230,11 +235,11 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
230
235
  }
231
236
  if (process.env.NODE_ENV === 'production' || process.env.UNI_MINIMIZE === 'true') {
232
237
  output.pathinfo = false
233
- }
234
-
235
- if (process.env.UNI_PLATFORM === 'mp-weixin' && process.env.NODE_ENV === 'production') {
236
- plugins.push(new UniTips())
237
- }
238
+ }
239
+
240
+ if (process.env.UNI_PLATFORM === 'mp-weixin' && process.env.NODE_ENV === 'production') {
241
+ plugins.push(new UniTips())
242
+ }
238
243
 
239
244
  return {
240
245
  mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
@@ -356,4 +361,4 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
356
361
  webpackConfig.plugins.delete('preload')
357
362
  webpackConfig.plugins.delete('prefetch')
358
363
  }
359
- }
364
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vue-cli-plugin-uni",
3
- "version": "2.0.2-3061520221228002",
3
+ "version": "2.0.2-3061720230112002",
4
4
  "description": "uni-app plugin for vue-cli 3",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -17,7 +17,7 @@
17
17
  "author": "fxy060608",
18
18
  "license": "Apache-2.0",
19
19
  "dependencies": {
20
- "@dcloudio/uni-stat": "^2.0.2-3061520221228002",
20
+ "@dcloudio/uni-stat": "^2.0.2-3061720230112002",
21
21
  "buffer-json": "^2.0.0",
22
22
  "clone-deep": "^4.0.1",
23
23
  "cross-env": "^5.2.0",
@@ -41,5 +41,5 @@
41
41
  "copy-webpack-plugin": ">=5",
42
42
  "postcss": ">=7"
43
43
  },
44
- "gitHead": "385d4400e9ac643a5cc3296bbb8145e745a9035f"
44
+ "gitHead": "7f96adf373b1ed1c454915aeedf9f02e80ce6cf7"
45
45
  }