webpack.mix.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // ------------------------------------ Dcat Admin -------------------------------------------
  34. function dcatPath(path) {
  35. return 'resources/assets/dcat/' + path;
  36. }
  37. function dcatDistPath(path) {
  38. return distPath + '/dcat/' + path;
  39. }
  40. // 复制第三方插件文件夹
  41. mix.copyDirectory(dcatPath('plugins'), dcatDistPath('plugins'));
  42. // 打包app.js
  43. mix.js(dcatPath('js/dcat-app.js'), dcatDistPath('js/dcat-app.js'));
  44. // 打包app.scss
  45. mix.sass(dcatPath('sass/dcat-app.scss'), dcatDistPath('css/dcat-app.css'));
  46. // 打包所有 extra 里面的所有js和css
  47. mixAssetsDir('dcat/extra/*.js', (src, dest) => mix.js(src, dest));
  48. mixAssetsDir('dcat/extra/*.scss', (src, dest) => mix.sass(src, dest.replace('scss', 'css')));