webpack.mix.js 2.2 KB

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