babel.config.js 1.7 KB

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