@dcloudio/vue-cli-plugin-hbuilderx 2.0.1-35420220803001 → 2.0.1-36220220916001

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.
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const webpack = require('webpack')
3
4
 
4
5
  const {
5
6
  getPlatformScss,
@@ -7,10 +8,6 @@ const {
7
8
  nvueCssPreprocessOptions
8
9
  } = require('@dcloudio/uni-cli-shared')
9
10
 
10
- const {
11
- sassLoaderVersion
12
- } = require('@dcloudio/uni-cli-shared/lib/scss')
13
-
14
11
  const nvueStyleLoader = {
15
12
  loader: '@dcloudio/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style'
16
13
  }
@@ -20,27 +17,33 @@ const preprocessLoader = {
20
17
  options: nvueCssPreprocessOptions
21
18
  }
22
19
 
20
+ const options = {
21
+ sourceMap: false
22
+ }
23
+ const plugins = [
24
+ require('postcss-import')({
25
+ resolve (id, basedir, importOptions) {
26
+ if (id.startsWith('~@/')) {
27
+ return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
28
+ } else if (id.startsWith('@/')) {
29
+ return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
30
+ } else if (id.startsWith('/') && !id.startsWith('//')) {
31
+ return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
32
+ }
33
+ return id
34
+ }
35
+ }),
36
+ require('@dcloudio/vue-cli-plugin-uni/packages/postcss')
37
+ ]
38
+ if (webpack.version[0] > 4) {
39
+ options.postcssOptions = { plugins }
40
+ } else {
41
+ options.parser = require('postcss-comment')
42
+ options.plugins = plugins
43
+ }
23
44
  const postcssLoader = {
24
45
  loader: 'postcss-loader',
25
- options: {
26
- sourceMap: false,
27
- parser: require('postcss-comment'),
28
- plugins: [
29
- require('postcss-import')({
30
- resolve (id, basedir, importOptions) {
31
- if (id.startsWith('~@/')) {
32
- return path.resolve(process.env.UNI_INPUT_DIR, id.substr(3))
33
- } else if (id.startsWith('@/')) {
34
- return path.resolve(process.env.UNI_INPUT_DIR, id.substr(2))
35
- } else if (id.startsWith('/') && !id.startsWith('//')) {
36
- return path.resolve(process.env.UNI_INPUT_DIR, id.substr(1))
37
- }
38
- return id
39
- }
40
- }),
41
- require('@dcloudio/vue-cli-plugin-uni/packages/postcss')
42
- ]
43
- }
46
+ options
44
47
  }
45
48
 
46
49
  // sass 全局变量
@@ -71,25 +74,15 @@ const sassLoader = {
71
74
  }
72
75
  }
73
76
 
74
- if (sassLoaderVersion < 8) {
75
- scssLoader.options.data = sassData
76
- scssLoader.options.outputStyle = 'expanded'
77
-
78
- sassLoader.options.data = sassData
79
- sassLoader.options.outputStyle = 'expanded'
80
- sassLoader.options.indentedSyntax = true
81
- } else {
82
- const name = sassLoaderVersion >= 9 ? 'additionalData' : 'prependData'
83
- scssLoader.options[name] = sassData
84
- scssLoader.options.sassOptions = {
85
- outputStyle: 'expanded'
86
- }
77
+ scssLoader.options.prependData = sassData
78
+ scssLoader.options.sassOptions = {
79
+ outputStyle: 'expanded'
80
+ }
87
81
 
88
- sassLoader.options[name] = sassData
89
- sassLoader.options.sassOptions = {
90
- outputStyle: 'expanded',
91
- indentedSyntax: true
92
- }
82
+ sassLoader.options.prependData = sassData
83
+ sassLoader.options.sassOptions = {
84
+ outputStyle: 'expanded',
85
+ indentedSyntax: true
93
86
  }
94
87
 
95
88
  const lessLoader = {
@@ -143,4 +136,4 @@ module.exports = [{
143
136
  }, {
144
137
  test: /\.styl(us)?$/,
145
138
  oneOf: createOneOf(stylusLoader)
146
- }]
139
+ }]
@@ -3,6 +3,7 @@ const path = require('path')
3
3
  const webpack = require('webpack')
4
4
  const VueLoaderPlugin = require('@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/plugin')
5
5
  const CopyWebpackPlugin = require('copy-webpack-plugin')
6
+ const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0])
6
7
  const TerserPlugin = require('terser-webpack-plugin')
7
8
 
8
9
  const {
@@ -12,6 +13,12 @@ const {
12
13
  getTemplatePath
13
14
  } = require('@dcloudio/uni-cli-shared')
14
15
  const fileLoader = require('@dcloudio/uni-cli-shared/lib/file-loader')
16
+ const {
17
+ compileI18nJsonStr
18
+ } = require('@dcloudio/uni-i18n')
19
+ const {
20
+ initI18nOptions
21
+ } = require('@dcloudio/uni-cli-shared/lib/i18n')
15
22
  const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3
16
23
  ? require('../packages/webpack-app-plus-plugin')
17
24
  : require('../packages/webpack-app-plus-nvue-plugin')
@@ -112,7 +119,10 @@ if (process.env.NODE_ENV === 'development') {
112
119
 
113
120
  // const excludeModuleReg = /node_modules(?!(\/|\\).*(weex).*)/
114
121
 
115
- const rules = [{
122
+ const rules = [webpack.version[0] > 4 ? {
123
+ test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
124
+ type: 'asset'
125
+ } : {
116
126
  test: /\.(png|jpg|gif|ttf|eot|woff|woff2)$/i,
117
127
  use: [fileLoader]
118
128
  }, {
@@ -194,7 +204,7 @@ rules.unshift({
194
204
  if (process.env.UNI_USING_V3_NATIVE) {
195
205
  try {
196
206
  const automatorJson = require.resolve('@dcloudio/uni-automator/dist/automator.json')
197
- plugins.push(new CopyWebpackPlugin([{
207
+ const patterns = [{
198
208
  from: automatorJson,
199
209
  to: '../.automator/' + (process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM) +
200
210
  '/.automator.json',
@@ -207,31 +217,46 @@ if (process.env.UNI_USING_V3_NATIVE) {
207
217
  }
208
218
  return ''
209
219
  }
210
- }]))
211
- } catch (e) {}
220
+ }]
221
+ plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? { patterns } : patterns))
222
+ } catch (e) { }
212
223
  }
213
224
 
214
225
  if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
215
226
  plugins.push(new WebpackUniMPPlugin())
216
227
  const assetsDir = 'static'
217
228
  const hybridDir = 'hybrid/html'
218
- const array = [{
229
+ const patterns = [{
219
230
  from: path.resolve(process.env.UNI_INPUT_DIR, assetsDir),
220
231
  to: assetsDir
221
232
  }]
222
233
  // 自动化测试时,不启用androidPrivacy.json
223
234
  if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
224
- const androidPrivacyPath = path.resolve(process.env.UNI_INPUT_DIR, 'androidPrivacy.json')
225
- if (fs.existsSync(androidPrivacyPath)) {
226
- array.push({
227
- from: androidPrivacyPath,
228
- to: 'androidPrivacy.json'
235
+ const fileName = 'androidPrivacy.json'
236
+ const context = path.resolve(process.env.UNI_INPUT_DIR)
237
+ if (fs.existsSync(path.join(context, fileName))) {
238
+ patterns.push({
239
+ from: fileName,
240
+ context,
241
+ to: fileName,
242
+ transform (content) {
243
+ const options = initI18nOptions(
244
+ process.env.UNI_PLATFORM,
245
+ process.env.UNI_INPUT_DIR,
246
+ false,
247
+ true
248
+ )
249
+ if (!options) {
250
+ return content
251
+ }
252
+ return compileI18nJsonStr(content.toString(), options)
253
+ }
229
254
  })
230
255
  }
231
256
  }
232
257
  const hybridHtmlPath = path.resolve(process.env.UNI_INPUT_DIR, hybridDir)
233
258
  if (fs.existsSync(hybridHtmlPath)) {
234
- array.push({
259
+ patterns.push({
235
260
  from: hybridHtmlPath,
236
261
  to: hybridDir
237
262
  })
@@ -242,7 +267,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
242
267
  const assets = modules + module + '/' + assetsDir
243
268
  const assetsPath = path.resolve(process.env.UNI_INPUT_DIR, assets)
244
269
  if (fs.existsSync(assetsPath)) {
245
- array.push({
270
+ patterns.push({
246
271
  from: assetsPath,
247
272
  to: assets
248
273
  })
@@ -250,7 +275,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
250
275
  const hybridHtml = modules + module + '/' + hybridDir
251
276
  const hybridHtmlPath = path.resolve(process.env.UNI_INPUT_DIR, hybridHtml)
252
277
  if (fs.existsSync(hybridHtmlPath)) {
253
- array.push({
278
+ patterns.push({
254
279
  from: hybridHtmlPath,
255
280
  to: hybridHtml
256
281
  })
@@ -258,12 +283,12 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
258
283
  })
259
284
 
260
285
  if (process.env.UNI_USING_NVUE_COMPILER) {
261
- array.push({
286
+ patterns.push({
262
287
  from: path.resolve(getTemplatePath(), 'common'),
263
288
  to: process.env.UNI_OUTPUT_DIR
264
289
  })
265
290
  } else if (process.env.UNI_USING_V3_NATIVE) {
266
- array.push({
291
+ patterns.push({
267
292
  from: path.resolve(getTemplatePath(), 'weex'),
268
293
  to: process.env.UNI_OUTPUT_DIR
269
294
  })
@@ -275,7 +300,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
275
300
  'weapp-tools/template/v8'
276
301
  )
277
302
  }
278
- array.push({
303
+ patterns.push({
279
304
  from: nativeTemplatePath,
280
305
  to: process.env.UNI_OUTPUT_DIR
281
306
  }, {
@@ -284,15 +309,17 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
284
309
  'weapp-tools/template/common'
285
310
  ),
286
311
  to: process.env.UNI_OUTPUT_DIR,
287
- ignore: [
288
- '*.js',
289
- '*.json',
290
- '__uniapppicker.html',
291
- '__uniappview.html'
292
- ]
312
+ globOptions: {
313
+ ignore: [
314
+ '*.js',
315
+ '*.json',
316
+ '__uniapppicker.html',
317
+ '__uniappview.html'
318
+ ]
319
+ }
293
320
  })
294
321
  }
295
- plugins.push(new CopyWebpackPlugin(array))
322
+ plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? { patterns } : patterns))
296
323
  }
297
324
 
298
325
  try {
@@ -305,7 +332,7 @@ try {
305
332
  dir: process.env.UNI_INPUT_DIR
306
333
  }))
307
334
  }
308
- } catch (e) {}
335
+ } catch (e) { }
309
336
 
310
337
  module.exports = function () {
311
338
  return {
@@ -322,8 +349,7 @@ module.exports = function () {
322
349
  performance: {
323
350
  hints: false
324
351
  },
325
- optimization: {
326
- namedModules: false,
352
+ optimization: Object.assign({
327
353
  minimizer: [
328
354
  new TerserPlugin({
329
355
  terserOptions: {
@@ -333,7 +359,7 @@ module.exports = function () {
333
359
  }
334
360
  })
335
361
  ]
336
- },
362
+ }, webpack.version[0] > 4 ? {} : { namedModules: false }),
337
363
  output: {
338
364
  path: process.env.UNI_OUTPUT_DIR,
339
365
  filename: '[name].js'
@@ -377,7 +403,7 @@ module.exports = function () {
377
403
  reasons: true,
378
404
  errorDetails: true
379
405
  },
380
- node: {
406
+ node: webpack.version[0] > 4 ? false : {
381
407
  global: false,
382
408
  Buffer: false,
383
409
  __filename: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/vue-cli-plugin-hbuilderx",
3
- "version": "2.0.1-35420220803001",
3
+ "version": "2.0.1-36220220916001",
4
4
  "description": "HBuilderX plugin for vue-cli 3",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -18,5 +18,5 @@
18
18
  "css": "~2.2.1",
19
19
  "escodegen": "^1.8.1"
20
20
  },
21
- "gitHead": "4616fac056201ef6f3db91c550c421c713fc973f"
21
+ "gitHead": "556ee9e4bafafe938d18573edf26cb67ba6b64ee"
22
22
  }
@@ -14,13 +14,10 @@ class WebpackAppPlusNVuePlugin {
14
14
  const changedFiles = []
15
15
  compiler.hooks.emit.tapAsync('webpack-uni-nvue', (compilation, callback) => {
16
16
  changedFiles.length = 0
17
- const changedChunks = compilation.chunks.filter(chunk => {
17
+ compilation.chunks.forEach(chunk => {
18
18
  const oldVersion = chunkVersions[chunk.name]
19
19
  chunkVersions[chunk.name] = chunk.hash
20
- return chunk.hash !== oldVersion
21
- })
22
- changedChunks.map(chunk => {
23
- if (Array.isArray(chunk.files)) {
20
+ if (chunk.hash !== oldVersion && Array.isArray(chunk.files)) {
24
21
  chunk.files.forEach(file => {
25
22
  !changedFiles.includes(file) && (changedFiles.push(file))
26
23
  })
@@ -44,13 +44,10 @@ class WebpackAppPlusPlugin {
44
44
  })
45
45
 
46
46
  compiler.hooks.emit.tapAsync('WebpackAppPlusPlugin', (compilation, callback) => {
47
- const changedChunks = compilation.chunks.filter(chunk => {
47
+ compilation.chunks.forEach(chunk => {
48
48
  const oldVersion = chunkVersions[chunk.name]
49
49
  chunkVersions[chunk.name] = chunk.hash
50
- return chunk.hash !== oldVersion
51
- })
52
- changedChunks.map(chunk => {
53
- if (Array.isArray(chunk.files)) {
50
+ if (chunk.hash !== oldVersion && Array.isArray(chunk.files)) {
54
51
  chunk.files.forEach(file => {
55
52
  if (isAppService) {
56
53
  !serviceChangedFiles.includes(file) && (serviceChangedFiles.push(file))