@dcloudio/vue-cli-plugin-uni 2.0.2-3090820231124001 → 2.0.2-4000620240325001

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.
@@ -31,17 +31,17 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
31
31
  }
32
32
  if (newOptions.fallback && newOptions.fallback.options) {
33
33
  const generator = {}
34
- const oldOptions = newOptions.fallback.options
35
- const keys = ['publicPath', 'outputPath']
36
- keys.forEach(key => {
37
- generator[key] = pathData => {
38
- const outputPath = oldOptions[key](null, pathData.module.request)
39
- const basename = path.basename(outputPath)
40
- return outputPath.substring(0, outputPath.length - basename.length)
41
- }
42
- })
34
+ const options = newOptions.fallback.options
35
+ // const keys = ['publicPath', 'outputPath']
36
+ // keys.forEach(key => {
37
+ // generator[key] = pathData => {
38
+ // const outputPath = oldOptions[key](null, pathData.module.request)
39
+ // const basename = path.basename(outputPath)
40
+ // return outputPath.substring(0, outputPath.length - basename.length)
41
+ // }
42
+ // })
43
43
  generator.filename = pathData => {
44
- return path.basename(pathData.module.request)
44
+ return options.name(pathData.module.request)
45
45
  }
46
46
  webpackConfig.module.rule(staticType).set('generator', generator)
47
47
  }
@@ -1,4 +1,3 @@
1
- const fs = require('fs')
2
1
  const path = require('path')
3
2
  const webpack = require('webpack')
4
3
  const CopyWebpackPlugin = require('copy-webpack-plugin')
@@ -14,10 +13,6 @@ function resolve (dir) {
14
13
  return path.resolve(__dirname, '..', dir)
15
14
  }
16
15
 
17
- function resolveModule (dir) {
18
- return path.resolve(process.env.UNI_CLI_CONTEXT, './node_modules', dir)
19
- }
20
-
21
16
  module.exports = function configureWebpack (platformOptions, manifestPlatformOptions, vueOptions, api) {
22
17
  const {
23
18
  runByHBuilderX, // 使用 HBuilderX 运行
@@ -97,82 +92,30 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
97
92
  matchUse.push(loader)
98
93
  }
99
94
 
100
- const userTsConfigJson = path.resolve(process.env.UNI_INPUT_DIR, 'tsconfig.json')
101
- const defaultTsConfigJson = path.resolve(process.env.UNI_CLI_CONTEXT, 'tsconfig.json')
102
-
103
- const tsConfigJsonFile = fs.existsSync(userTsConfigJson) ? userTsConfigJson : defaultTsConfigJson
104
-
105
- const context = isInHBuilderX ? process.env.UNI_INPUT_DIR : process.env.UNI_CLI_CONTEXT
106
-
107
- const tsLoaderOptions = {
108
- context,
109
- configFile: tsConfigJsonFile,
110
- compilerOptions: {
111
- baseUrl: context,
112
- typeRoots: [
113
- resolveModule('@dcloudio/types'),
114
- resolveModule('@types'),
115
- path.resolve(process.env.UNI_CLI_CONTEXT, 'types')
116
- ],
117
- types: [
118
- 'uni-app',
119
- 'uni-app-vue2',
120
- 'webpack-env'
121
- ],
122
- paths: {
123
- '@/*': [
124
- path.join(process.env.UNI_INPUT_DIR, '*')
125
- ],
126
- vue: [
127
- resolveModule('vue')
128
- ],
129
- vuex: [
130
- resolveModule('vuex')
131
- ],
132
- 'vue-class-component': [
133
- resolveModule('vue-class-component')
134
- ],
135
- 'vue-property-decorator': [
136
- resolveModule('vue-property-decorator')
137
- ],
138
- tslib: [
139
- resolveModule('tslib')
140
- ],
141
- 'mpvue-page-factory': [
142
- resolveModule('@dcloudio/vue-cli-plugin-uni/packages/mpvue-page-factory')
143
- ],
144
- '@vue/composition-api': [
145
- resolveModule('@dcloudio/vue-cli-plugin-uni/packages/@vue/composition-api')
146
- ],
147
- '@dcloudio/uni-app': [
148
- resolveModule('@dcloudio/uni-app')
149
- ]
150
- }
151
- },
152
- errorFormatter (error, colors) {
153
- const messageColor = error.severity === 'warning' ? colors.bold.yellow : colors.bold.red
154
- const filePath = path.relative(process.env.UNI_INPUT_DIR, error.file).replace('.vue.ts', '.vue')
155
- if (error.code === 2307 && error.content.includes('.vue')) {
156
- error.content = error.content.replace('Cannot find module ', '') +
157
- ' script 节点必须使用 lang="ts",文档参考地址:https://uniapp.dcloud.io/frame?id=vue-ts'
158
- }
159
- return messageColor(
160
- `[tsl] ERROR at ${filePath}:${error.line}
161
- TS${error.code}:${error.content}`
162
- )
163
- }
164
- }
95
+ const tsLoaderOptions = require('./util').getTsLoadOptions()
165
96
 
166
- function updateTsLoader (rawRules, fakeFile, loader) {
97
+ function updateTsLoader (rawRules, fakeFile, loader, appendUTS = false) {
167
98
  const matchRule = rawRules.find(createMatcher(fakeFile))
168
99
  if (matchRule && matchRule.use) {
169
100
  if (isInHBuilderX) {
170
101
  matchRule.use.forEach(matchUse => {
171
102
  if (matchUse.loader.includes('ts-loader')) {
172
103
  Object.assign(matchUse.options, tsLoaderOptions)
104
+ if (appendUTS) {
105
+ if (!Array.isArray(matchUse.options.appendTsSuffixTo)) {
106
+ matchUse.options.appendTsSuffixTo = [matchUse.options.appendTsSuffixTo]
107
+ }
108
+ matchUse.options.appendTsSuffixTo.push(/\.uts$/)
109
+ }
173
110
  }
174
111
  })
175
112
  }
113
+ if (appendUTS) {
114
+ if (!Array.isArray(matchRule.test)) {
115
+ matchRule.test = [matchRule.test]
116
+ }
117
+ matchRule.test.push(/\.uts$/)
118
+ }
176
119
  matchRule.use.push(loader)
177
120
  }
178
121
  }
@@ -229,7 +172,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
229
172
  updateTsLoader(rawRules, 'foo.ts', {
230
173
  loader: resolve('packages/webpack-preprocess-loader'),
231
174
  options: jsPreprocessOptions
232
- })
175
+ }, true)
233
176
  updateTsLoader(rawRules, 'foo.tsx', {
234
177
  loader: resolve('packages/webpack-preprocess-loader'),
235
178
  options: jsPreprocessOptions
@@ -261,7 +204,15 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
261
204
  .parseUniExtApis(false, process.env.UNI_UTS_PLATFORM, 'javascript')
262
205
  const keys = Object.keys(uniExtApis)
263
206
  if (keys.length) {
264
- plugins.push(new webpack.ProvidePlugin(uniExtApis))
207
+ const provides = {}
208
+ keys.forEach(name => {
209
+ const provide = uniExtApis[name]
210
+ if (Array.isArray(provide) && provide.length === 3) {
211
+ provide.pop()
212
+ }
213
+ provides[name] = provide
214
+ })
215
+ plugins.push(new webpack.ProvidePlugin(provides))
265
216
  }
266
217
  }
267
218
  if (!process.env.UNI_SUBPACKGE || !process.env.UNI_MP_PLUGIN) {
@@ -449,4 +400,4 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
449
400
  watchOptions: require('./util').getWatchOptions()
450
401
  }, platformWebpackConfig)
451
402
  }
452
- }
403
+ }
package/lib/h5/index.js CHANGED
@@ -194,4 +194,4 @@ module.exports = {
194
194
  require('./cssnano-options')(webpackConfig)
195
195
  }
196
196
  }
197
- }
197
+ }
package/lib/util.js CHANGED
@@ -1,4 +1,6 @@
1
+ const fs = require('fs')
1
2
  const path = require('path')
3
+
2
4
  const {
3
5
  pathToGlob
4
6
  } = require('@dcloudio/uni-cli-shared/lib/util')
@@ -37,5 +39,79 @@ module.exports = {
37
39
  path.resolve(process.env.UNI_INPUT_DIR, 'cloudfunctions-tcb')
38
40
  ]
39
41
  }
42
+ },
43
+ getTsLoadOptions () {
44
+ const {
45
+ isInHBuilderX // 在 HBuilderX 的插件中
46
+ } = require('@dcloudio/uni-cli-shared')
47
+ const userTsConfigJson = path.resolve(process.env.UNI_INPUT_DIR, 'tsconfig.json')
48
+ const defaultTsConfigJson = path.resolve(process.env.UNI_CLI_CONTEXT, 'tsconfig.json')
49
+
50
+ const tsConfigJsonFile = fs.existsSync(userTsConfigJson) ? userTsConfigJson : defaultTsConfigJson
51
+
52
+ const context = isInHBuilderX ? process.env.UNI_INPUT_DIR : process.env.UNI_CLI_CONTEXT
53
+
54
+ function resolveModule (dir) {
55
+ return path.resolve(process.env.UNI_CLI_CONTEXT, './node_modules', dir)
56
+ }
57
+
58
+ return {
59
+ context,
60
+ configFile: tsConfigJsonFile,
61
+ compilerOptions: {
62
+ baseUrl: context,
63
+ typeRoots: [
64
+ resolveModule('@dcloudio/types'),
65
+ resolveModule('@types'),
66
+ path.resolve(process.env.UNI_CLI_CONTEXT, 'types')
67
+ ],
68
+ types: [
69
+ 'uni-app',
70
+ 'uni-app-vue2',
71
+ 'webpack-env'
72
+ ],
73
+ paths: {
74
+ '@/*': [
75
+ path.join(process.env.UNI_INPUT_DIR, '*')
76
+ ],
77
+ vue: [
78
+ resolveModule('vue')
79
+ ],
80
+ vuex: [
81
+ resolveModule('vuex')
82
+ ],
83
+ 'vue-class-component': [
84
+ resolveModule('vue-class-component')
85
+ ],
86
+ 'vue-property-decorator': [
87
+ resolveModule('vue-property-decorator')
88
+ ],
89
+ tslib: [
90
+ resolveModule('tslib')
91
+ ],
92
+ 'mpvue-page-factory': [
93
+ resolveModule('@dcloudio/vue-cli-plugin-uni/packages/mpvue-page-factory')
94
+ ],
95
+ '@vue/composition-api': [
96
+ resolveModule('@dcloudio/vue-cli-plugin-uni/packages/@vue/composition-api')
97
+ ],
98
+ '@dcloudio/uni-app': [
99
+ resolveModule('@dcloudio/uni-app')
100
+ ]
101
+ }
102
+ },
103
+ errorFormatter (error, colors) {
104
+ const messageColor = error.severity === 'warning' ? colors.bold.yellow : colors.bold.red
105
+ const filePath = path.relative(process.env.UNI_INPUT_DIR, error.file).replace('.vue.ts', '.vue')
106
+ if (error.code === 2307 && error.content.includes('.vue')) {
107
+ error.content = error.content.replace('Cannot find module ', '') +
108
+ ' script 节点必须使用 lang="ts",文档参考地址:https://uniapp.dcloud.io/frame?id=vue-ts'
109
+ }
110
+ return messageColor(
111
+ `[tsl] ERROR at ${filePath}:${error.line}
112
+ TS${error.code}:${error.content}`
113
+ )
114
+ }
115
+ }
40
116
  }
41
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vue-cli-plugin-uni",
3
- "version": "2.0.2-3090820231124001",
3
+ "version": "2.0.2-4000620240325001",
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-3090820231124001",
20
+ "@dcloudio/uni-stat": "^2.0.2-4000620240325001",
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": "c32691147b539a337d6bca396ba42a6c3ddc1dbf"
44
+ "gitHead": "2f9ba8ff3e3f185745faa67dd4eefaef7f3db374"
45
45
  }