Blame view

node_modules/we-cropper/scripts/build/config.js 1.53 KB
ce4c83ff   wxy   初始提交
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  const path = require('path')
  const buble = require('rollup-plugin-buble')
  const replace = require('rollup-plugin-replace')
  const npmResolve = require('rollup-plugin-node-resolve')
  const common = require('rollup-plugin-commonjs')
  const copy = require('rollup-plugin-copy')
  const version = process.env.VERSION || require('../../package.json').version
  const banner =
    `/**
   * we-cropper v${version}
   * (c) ${new Date().getFullYear()} dlhandsome
   * @license MIT
   */`
  
  const resolve = _path => path.resolve(__dirname, '../../', _path)
  
  const configs = {
    umdDev: {
      input: resolve('src/main.js'),
      file: resolve('dist/we-cropper.js'),
      format: 'umd',
      env: 'development'
    },
    umdProd: {
      input: resolve('src/main.js'),
      file: resolve('dist/we-cropper.min.js'),
      format: 'umd',
      env: 'production'
    }
  }
  
  function genConfig (name) {
    const opts = configs[name]
    const config = {
      input: opts.input,
      plugins: [
        npmResolve(),
        common(),
        replace({
          __VERSION__: JSON.stringify(version)
        }),
        buble(),
        copy({
          'dist/': 'example/we-cropper/',
          verbose: true
        })
      ],
      output: {
        banner,
        file: opts.file,
        format: opts.format,
        name: 'WeCropper'
      }
    }
    
    return config
  }
  
  function mapValues (obj, fn) {
    const res = {}
    Object.keys(obj).forEach(key => {
      res[key] = fn(obj[key], key)
    })
    return res
  }
  
  if (process.env.TARGET) {
    module.exports = genConfig(process.env.TARGET)
  } else {
    module.exports = Object.keys(configs).map(genConfig)
  }