config.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /// 阅读 api.d.ts 查看文档
  2. ///<reference path="api.d.ts"/>
  3. import * as path from 'path';
  4. import { UglifyPlugin, IncrementCompilePlugin, CompilePlugin, ManifestPlugin, ExmlPlugin, EmitResConfigFilePlugin, TextureMergerPlugin, RenamePlugin, CleanPlugin } from 'built-in';
  5. import { WxgamePlugin } from './wxgame/wxgame';
  6. import { BricksPlugin } from './bricks/bricks';
  7. import { CustomPlugin } from './myplugin';
  8. import { ResPlugin } from './resplugin';
  9. const config: ResourceManagerConfig = {
  10. buildConfig: (params) => {
  11. const { target, command, projectName, version } = params;
  12. if (command == 'build') {
  13. const outputDir = '.';
  14. return {
  15. outputDir,
  16. commands: [
  17. // new EmitResConfigFilePlugin({
  18. // output: "resource/default.res.json",
  19. // typeSelector: config.typeSelector,
  20. // nameSelector: p => path.basename(p).replace(/\./gi, "_"),
  21. // groupSelector: p => "preload"
  22. // }),
  23. new ExmlPlugin('debug'), // 非 EUI 项目关闭此设置
  24. new IncrementCompilePlugin(),
  25. ]
  26. }
  27. }
  28. else if (command == 'publish') {
  29. const outputDir = `bin-release/web/${version}`;
  30. return {
  31. outputDir,
  32. commands: [
  33. new CustomPlugin(),
  34. new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }),
  35. new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
  36. new UglifyPlugin([{
  37. sources: ["main.js"],
  38. target: "main.min.js"
  39. }]),
  40. new RenamePlugin({
  41. verbose: true, hash: 'crc32', matchers: [
  42. { from: "**/*.js", to: "[path][name]_[hash].[ext]" }
  43. ]
  44. }),
  45. new ResPlugin(),
  46. new ManifestPlugin({ output: "manifest.json" })
  47. ]
  48. }
  49. }
  50. else {
  51. throw `unknown command : ${params.command}`
  52. }
  53. },
  54. mergeSelector: (path) => {
  55. if (path.indexOf("assets/bitmap/") >= 0) {
  56. return "assets/bitmap/sheet.sheet"
  57. }
  58. else if (path.indexOf("armature") >= 0 && path.indexOf(".json") >= 0) {
  59. return "assets/armature/1.zip";
  60. }
  61. },
  62. typeSelector: (path) => {
  63. const ext = path.substr(path.lastIndexOf(".") + 1);
  64. const typeMap = {
  65. "jpg": "image",
  66. "png": "image",
  67. "webp": "image",
  68. "json": "json",
  69. "fnt": "font",
  70. "pvr": "pvr",
  71. "mp3": "sound",
  72. "zip": "zip",
  73. "sheet": "sheet",
  74. "exml": "text"
  75. }
  76. let type = typeMap[ext];
  77. if (type == "json") {
  78. if (path.indexOf("sheet") >= 0) {
  79. type = "sheet";
  80. } else if (path.indexOf("movieclip") >= 0) {
  81. type = "movieclip";
  82. };
  83. }
  84. return type;
  85. }
  86. }
  87. export = config;