fis-conf.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. var version = '';
  2. var path = '/zt2018/wxwy1809/';
  3. fis.set('project.files', ['*.html', 'map.json']);
  4. fis.set('project.exclude', ['tpl/**.tmpl', '_dest/**']);
  5. fis.hook('commonjs', {
  6. baseUrl: './src/modules',
  7. extList: ['.js']
  8. });
  9. // 开启同名依赖
  10. fis.match('/src/modules/**', {
  11. useSameNameRequire: true
  12. });
  13. // fis.match('/lib/**.js', {
  14. // release: version + '/$1',
  15. // packTo: 'lib.js'
  16. // });
  17. // 允许你在 js 中直接 require css+文件
  18. fis.match('*.{js,es}', {
  19. rExt: '.js',
  20. parser: fis.plugin('es6-babel'),
  21. preprocessor: [
  22. fis.plugin('js-require-file'),
  23. fis.plugin('js-require-css', {
  24. mode: 'dependency'
  25. })
  26. ]
  27. });
  28. /*设置发布路径*/
  29. fis.match(/^\/src\/(.*)/i, {
  30. release: version + '/$1',
  31. // url: version + '/$1'
  32. });
  33. // 配置图片压缩
  34. fis.match('**.png', {
  35. optimizer: fis.plugin('png-compressor', {
  36. type: 'pngquant'
  37. })
  38. });
  39. /*Sprite背景图移到staticPub/images*/
  40. fis.match(/^\/sass\/(.*\.(png|jpg|gif|jpeg))$/i, {
  41. release: 'img/sprite/$1',
  42. url: 'img/sprite/$1'
  43. });
  44. fis.match(/^\/src\/sass\/((.*)\.(css|less|scss|sass))$/i, {
  45. rExt: '.css',
  46. useSprite: true,
  47. parser: fis.plugin('node-sass'),
  48. postprocessor: fis.plugin('autoprefixer', {
  49. browsers: ['> 1%', 'last 2 versions'],
  50. cascade: true
  51. }),
  52. release: version + '/css/$1',
  53. url: './css/$1'
  54. }).match('_*.scss', {
  55. release: false
  56. })
  57. /*对CSS中的图片进行合并,包括html中的内联样式*/
  58. fis.match('*.{css,html,tpl}', {
  59. useSprite: true,
  60. });
  61. fis.match('*.tmpl', {
  62. isJsLike: true,
  63. release: false,
  64. parser: fis.plugin('utc')
  65. })
  66. fis.match(/^\/src\/modules\/(.*\.js)$/i, {
  67. isMod: true
  68. });
  69. /*css压缩*/
  70. fis.match('*.css', {
  71. optimizer: fis.plugin('clean-css')
  72. });
  73. /*启用 fis-spriter-csssprites 插件*/
  74. fis.match('::package', {
  75. spriter: fis.plugin('csssprites',{
  76. margin: 20,
  77. htmlUseSprite: true,/*开启模板内联css处理*/
  78. styleReg: /(<style(?:(?=\s)[\s\S]*?["'\s\w\/\-]>|>))([\s\S]*?)(<\/style\s*>|$)/ig
  79. }),
  80. postpackager: fis.plugin('loader', {
  81. resourceType: 'commonJs',
  82. useInlineMap: true // 资源映射表内嵌
  83. })
  84. });
  85. /*图片文件域名配置*/
  86. fis.media('dev').match('*.{jpg,png,jpeg,gif,css,js}', {
  87. domain: '../../',
  88. });
  89. fis.media('prod').match('*.{jpg,png,jpeg,gif,css,scss,js,woff,ttf,svg,eot}', {
  90. domain: '//pub.dwstatic.com' + path,
  91. }).match('::package', {
  92. postpackager: fis.plugin('loader', {
  93. allInOne: {
  94. resourceType: 'mod',
  95. js: function (file) {
  96. return version + 'js/' + file.filename + ".js";
  97. },
  98. css: function (file) {
  99. return version + 'css/' + file.filename + ".css";
  100. }
  101. },
  102. resoucemap: version + 'js/${filepath}_map.js',
  103. })
  104. }).match('*.js', {
  105. optimizer: fis.plugin('uglify-js',{
  106. mangle: {
  107. except: 'exports, module, require, define'
  108. }
  109. })
  110. }).match(/^\/src\/sass\/((.*)\.(css|less|scss|sass))$/i, {
  111. url: version + 'css/$1',
  112. optimizer: fis.plugin('clean-css'),
  113. useHash: true
  114. }).match('sass/(**.png)', {
  115. release: version + 'img/sprite/$1'
  116. });