'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const {
  done
} = require('@vue/cli-shared-utils')
const { showRunPrompt } = require('@dcloudio/uni-cli-shared')
 
class WebpackAppPlusNVuePlugin {
  apply (compiler) {
    let isFirst = !process.env.UNI_USING_NATIVE && !process.env.UNI_USING_V3_NATIVE
 
    if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
      isFirst = true
    }
 
    const chunkVersions = {}
    const changedFiles = []
    compiler.hooks.emit.tapAsync('webpack-uni-nvue', (compilation, callback) => {
      changedFiles.length = 0
      compilation.chunks.forEach(chunk => {
        const oldVersion = chunkVersions[chunk.name]
        chunkVersions[chunk.name] = chunk.hash
        if (chunk.hash !== oldVersion && Array.isArray(chunk.files)) {
          chunk.files.forEach(file => {
            !changedFiles.includes(file) && (changedFiles.push(file))
          })
        }
      })
      callback()
    })
    compiler.hooks.done.tapPromise('webpack-uni-nvue', compilation => {
      return new Promise((resolve, reject) => {
        if (isFirst) {
          isFirst = false
        } else {
          if (process.env.NODE_ENV === 'development') {
            if (
              changedFiles.length > 0 &&
              !changedFiles.find(file => file === 'app-config.js' || file === 'app-service.js')
            ) {
              done('Build complete. PAGES:' + JSON.stringify(changedFiles))
            } else {
              done('Build complete. Watching for changes...')
              showRunPrompt()
            }
          } else {
            done('Build complete. ')
            showRunPrompt()
          }
        }
        resolve()
      })
    })
  }
}
 
module.exports = WebpackAppPlusNVuePlugin