config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const buble = require('rollup-plugin-buble');
  2. const replace = require('rollup-plugin-replace');
  3. const path = require('path');
  4. const banner = `
  5. /* Tencent is pleased to support the open source community by making WePY available.
  6. * Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
  7. *
  8. * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  9. * http://opensource.org/licenses/MIT
  10. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  11. */`;
  12. const resolvePkgInfo = pkg => {
  13. const pkgPath = path.resolve(__dirname, '../packages', pkg, 'package.json');
  14. return require(pkgPath);
  15. };
  16. const builds = {
  17. core: {
  18. entry: 'packages/core/index.js',
  19. dest: 'packages/core/dist/wepy.js',
  20. env: 'development',
  21. format: 'cjs',
  22. version: resolvePkgInfo('core').version,
  23. banner
  24. },
  25. 'core-ant': {
  26. entry: 'packages/core/index.ant.js',
  27. dest: 'packages/core/dist/wepy.ant.js',
  28. env: 'development',
  29. format: 'cjs',
  30. version: resolvePkgInfo('core').version,
  31. banner
  32. },
  33. redux: {
  34. entry: 'packages/redux/index.js',
  35. dest: 'packages/redux/dist/index.js',
  36. env: 'development',
  37. format: 'cjs',
  38. version: resolvePkgInfo('redux').version,
  39. banner
  40. },
  41. x: {
  42. entry: 'packages/x/index.js',
  43. dest: 'packages/x/dist/index.js',
  44. env: 'development',
  45. format: 'cjs',
  46. version: resolvePkgInfo('x').version,
  47. banner
  48. },
  49. 'use-promisify': {
  50. entry: 'packages/use-promisify/index.js',
  51. dest: 'packages/use-promisify/dist/index.js',
  52. env: 'development',
  53. format: 'cjs',
  54. version: resolvePkgInfo('use-promisify').version,
  55. banner
  56. },
  57. 'use-intercept': {
  58. entry: 'packages/use-intercept/index.js',
  59. dest: 'packages/use-intercept/dist/index.js',
  60. env: 'development',
  61. format: 'cjs',
  62. version: resolvePkgInfo('use-intercept').version,
  63. banner
  64. }
  65. };
  66. function getConfig(name) {
  67. let opt = builds[name];
  68. let config = {
  69. input: opt.entry,
  70. external: opt.external,
  71. plugins: [
  72. buble({
  73. objectAssign: 'Object.assign'
  74. })
  75. ].concat(opt.options || []),
  76. output: {
  77. file: opt.dest,
  78. format: opt.format,
  79. banner: opt.banner,
  80. name: opt.moduleName || 'WePY'
  81. }
  82. };
  83. if (opt.env) {
  84. config.plugins.push(
  85. replace({
  86. 'process.env.NODE_ENV': JSON.stringify(opt.env),
  87. __VERSION__: JSON.stringify(opt.version)
  88. })
  89. );
  90. }
  91. return config;
  92. }
  93. if (process.env.TARGET) {
  94. module.exports = getConfig(process.env.TARGET);
  95. } else {
  96. exports.getBuild = getConfig;
  97. exports.getAllBuilds = () => Object.keys(builds).map(getConfig);
  98. }