Advertisement
METAJIJI

npm build.js

Sep 7th, 2022
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.29 KB | Software | 0 0
  1. const path = require('path');
  2. const fs = require('fs');
  3.  
  4. const vendor_dir = path.resolve(__dirname, 'public/static/vendor')
  5.  
  6. function copyFromNodeModules(src, dest) {
  7.     /*
  8.      * src - relative from node_modules directory
  9.      * dest - should be absolute path
  10.      */
  11.     for (let dir in module.paths) {
  12.         let file = path.resolve(module.paths[dir], src);
  13.         if (fs.existsSync(file)) {
  14.             fs.mkdirSync(path.dirname(dest), {recursive: true});
  15.             fs.copyFile(file, dest, (err) => {
  16.                 if (err) {
  17.                     throw err;
  18.                 }
  19.                 console.log(`Copy file: "${file}" to: "${dest}"`);
  20.             });
  21.             return true
  22.         }
  23.     }
  24.     throw new Error(`File: "${src}" not found in paths: ${module.paths}`)
  25. }
  26.  
  27. // Cleanup
  28. fs.rmSync(vendor_dir, {recursive: true, force: true});
  29. fs.mkdirSync(vendor_dir, {recursive: true});
  30.  
  31. // Copy files
  32. copyFromNodeModules('bootstrap/dist/js/bootstrap.bundle.min.js', path.resolve(vendor_dir, 'bootstrap/bootstrap.bundle.min.js'));
  33. copyFromNodeModules('bootstrap/dist/css/bootstrap.min.css', path.resolve(vendor_dir, 'bootstrap/bootstrap.min.css'));
  34. copyFromNodeModules('bootstrap/dist/css/bootstrap.min.css.map', path.resolve(vendor_dir, 'bootstrap/bootstrap.min.css.map'));
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement