webpack.mix.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const mix = require('laravel-mix');
  2. require('dotenv').config();
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Mix Asset Management
  6. |--------------------------------------------------------------------------
  7. |
  8. | Mix provides a clean, fluent API for defining some Webpack build steps
  9. | for your Laravel application. By default, we are compiling the Sass
  10. | file for the application as well as bundling up all the JS files.
  11. |
  12. */
  13. const glob = require('glob')
  14. let theme = null;
  15. let distPath = mix.inProduction() ? 'resources/dist' : 'resources/pre-dist';
  16. function mixAssetsDir(query, cb) {
  17. (glob.sync('resources/assets/' + query) || []).forEach(f => {
  18. f = f.replace(/[\\\/]+/g, '/');
  19. cb(f, f.replace('resources/assets', distPath));
  20. });
  21. }
  22. function themeCss(path) {
  23. let sf = theme ? '-'+theme : '';
  24. return `${distPath}/${path}${sf}.css`
  25. }
  26. function dcatPath(path) {
  27. return 'resources/assets/dcat/' + path;
  28. }
  29. function dcatDistPath(path) {
  30. return distPath + '/dcat/' + path;
  31. }
  32. /*
  33. |--------------------------------------------------------------------------
  34. | Dcat Admin assets
  35. |--------------------------------------------------------------------------
  36. */
  37. mix.copyDirectory('resources/assets/images', distPath + '/images');
  38. mix.copyDirectory('resources/assets/fonts', distPath + '/fonts');
  39. mix.copyDirectory('resources/assets/vendors', distPath + '/vendors');
  40. // AdminLTE3.0
  41. mix.sass('resources/assets/adminlte/scss/AdminLTE.scss', themeCss('adminlte/adminlte')).sourceMaps();
  42. mix.js('resources/assets/adminlte/js/AdminLTE.js', distPath + '/adminlte/adminlte.js').sourceMaps();
  43. // 复制第三方插件文件夹
  44. mix.copyDirectory(dcatPath('plugins'), dcatDistPath('plugins'));
  45. // 打包app.js
  46. mix.js(dcatPath('js/dcat-app.js'), dcatDistPath('js/dcat-app.js')).sourceMaps();
  47. // 打包app.scss
  48. mix.sass(dcatPath('sass/dcat-app.scss'), themeCss('dcat/css/dcat-app')).sourceMaps();
  49. // 打包所有 extra 里面的所有js和css
  50. mixAssetsDir('dcat/extra/*.js', (src, dest) => mix.js(src, dest));
  51. mixAssetsDir('dcat/extra/*.scss', (src, dest) => {
  52. if (theme) {
  53. return mix.sass(src, dest.replace('\.scss', '-'+theme+'.css'))
  54. }
  55. return mix.sass(src, dest.replace('scss', 'css'))
  56. });
  57. // 皮肤
  58. // mixAssetsDir('dcat/sass/skins/*.scss', (src, dest) => {
  59. // if (theme) {
  60. // return mix.sass(src, dest.replace('\.scss', '-'+theme+'.css').replace(/sass/g, 'css'))
  61. // }
  62. //
  63. // return mix.sass(src, dest.replace(/sass/g, 'css').replace('scss', 'css'))
  64. // });