|
1 | | -const webpack = require('webpack') |
2 | | -const plugins = [] |
3 | | - |
4 | | -if (process.env.UNI_OPT_TREESHAKINGNG) { |
5 | | - plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js')) |
6 | | -} |
7 | | - |
8 | | -if ( |
9 | | - ( |
10 | | - process.env.UNI_PLATFORM === 'app-plus' && |
11 | | - process.env.UNI_USING_V8 |
12 | | - ) || |
13 | | - ( |
14 | | - process.env.UNI_PLATFORM === 'h5' && |
15 | | - process.env.UNI_H5_BROWSER === 'builtin' |
16 | | - ) |
17 | | -) { |
18 | | - const path = require('path') |
19 | | - |
20 | | - const isWin = /^win/.test(process.platform) |
21 | | - |
22 | | - const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) |
23 | | - |
24 | | - const input = normalizePath(process.env.UNI_INPUT_DIR) |
25 | | - try { |
26 | | - plugins.push([ |
27 | | - require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'), |
28 | | - { |
29 | | - file (file) { |
30 | | - file = normalizePath(file) |
31 | | - if (file.indexOf(input) === 0) { |
32 | | - return path.relative(input, file) |
33 | | - } |
34 | | - return false |
35 | | - } |
36 | | - } |
37 | | - ]) |
38 | | - } catch (e) { } |
39 | | -} |
40 | | - |
41 | | -process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui'] |
42 | | -process.UNI_LIBRARIES.forEach(libraryName => { |
43 | | - plugins.push([ |
44 | | - 'import', |
45 | | - { |
46 | | - 'libraryName': libraryName, |
47 | | - 'customName': (name) => { |
48 | | - return `${libraryName}/lib/${name}/${name}` |
49 | | - } |
50 | | - } |
51 | | - ]) |
52 | | -}) |
53 | | - |
54 | | -if (process.env.UNI_PLATFORM !== 'h5') { |
55 | | - plugins.push('@babel/plugin-transform-runtime') |
56 | | -} |
57 | | - |
58 | | -const config = { |
59 | | - presets: [ |
60 | | - [ |
61 | | - '@vue/app', |
62 | | - { |
63 | | - modules: webpack.version[0] > 4 ? 'auto' : 'commonjs', |
64 | | - useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry' |
65 | | - } |
66 | | - ] |
67 | | - ], |
68 | | - plugins |
69 | | -} |
70 | | - |
71 | | -const UNI_H5_TEST = '**/@dcloudio/uni-h5/dist/index.umd.min.js' |
72 | | -if (process.env.NODE_ENV === 'production') { |
73 | | - config.overrides = [{ |
74 | | - test: UNI_H5_TEST, |
75 | | - compact: true, |
76 | | - }] |
77 | | -} else { |
78 | | - config.ignore = [UNI_H5_TEST] |
79 | | -} |
80 | | - |
81 | | -module.exports = config |
| 1 | +const webpack = require('webpack') |
| 2 | +const plugins = [] |
| 3 | + |
| 4 | +if (process.env.UNI_OPT_TREESHAKINGNG) { |
| 5 | + plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js')) |
| 6 | +} |
| 7 | + |
| 8 | +if ( |
| 9 | + ( |
| 10 | + process.env.UNI_PLATFORM === 'app-plus' && |
| 11 | + process.env.UNI_USING_V8 |
| 12 | + ) || |
| 13 | + ( |
| 14 | + process.env.UNI_PLATFORM === 'h5' && |
| 15 | + process.env.UNI_H5_BROWSER === 'builtin' |
| 16 | + ) |
| 17 | +) { |
| 18 | + const path = require('path') |
| 19 | + |
| 20 | + const isWin = /^win/.test(process.platform) |
| 21 | + |
| 22 | + const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) |
| 23 | + |
| 24 | + const input = normalizePath(process.env.UNI_INPUT_DIR) |
| 25 | + try { |
| 26 | + plugins.push([ |
| 27 | + require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'), |
| 28 | + { |
| 29 | + file (file) { |
| 30 | + file = normalizePath(file) |
| 31 | + if (file.indexOf(input) === 0) { |
| 32 | + return path.relative(input, file) |
| 33 | + } |
| 34 | + return false |
| 35 | + } |
| 36 | + } |
| 37 | + ]) |
| 38 | + } catch (e) { } |
| 39 | +} |
| 40 | + |
| 41 | +process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui'] |
| 42 | +process.UNI_LIBRARIES.forEach(libraryName => { |
| 43 | + plugins.push([ |
| 44 | + 'import', |
| 45 | + { |
| 46 | + 'libraryName': libraryName, |
| 47 | + 'customName': (name) => { |
| 48 | + return `${libraryName}/lib/${name}/${name}` |
| 49 | + } |
| 50 | + } |
| 51 | + ]) |
| 52 | +}) |
| 53 | + |
| 54 | +if (process.env.UNI_PLATFORM !== 'h5') { |
| 55 | + plugins.push('@babel/plugin-transform-runtime') |
| 56 | +} |
| 57 | + |
| 58 | +const config = { |
| 59 | + presets: [ |
| 60 | + [ |
| 61 | + '@vue/app', |
| 62 | + { |
| 63 | + modules: webpack.version[0] > 4 ? 'auto' : 'commonjs', |
| 64 | + useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry' |
| 65 | + } |
| 66 | + ] |
| 67 | + ], |
| 68 | + plugins |
| 69 | +} |
| 70 | + |
| 71 | +const UNI_H5_TEST = '**/@dcloudio/uni-h5/dist/index.umd.min.js' |
| 72 | +if (process.env.NODE_ENV === 'production') { |
| 73 | + config.overrides = [{ |
| 74 | + test: UNI_H5_TEST, |
| 75 | + compact: true, |
| 76 | + }] |
| 77 | +} else { |
| 78 | + config.ignore = [UNI_H5_TEST] |
| 79 | +} |
| 80 | + |
| 81 | +module.exports = config |
0 commit comments