webpack.common.js 890 B

1234567891011121314151617181920212223242526272829303132
  1. const fs = require('fs')
  2. const path = require('path')
  3. const htmlPath = './src/'//遍历的html文件路径
  4. const jsPath = htmlPath + 'js/'//遍历的js文件路径
  5. function readEntryFile() {
  6. return _readDiffPath(htmlPath, /.html$/)
  7. }
  8. function _readDiffPath(path, reg) {
  9. var ret = []
  10. if (fs.existsSync(path)) {
  11. fs.readdirSync(path).forEach(function (filename) {
  12. if (reg.test(filename)) {
  13. var name = filename.slice(0, filename.lastIndexOf('.'))
  14. ret.push({
  15. path: path,
  16. name: name,
  17. jsentry: jsPath + name + '.js',
  18. htmlentry: path + filename
  19. })
  20. }
  21. })
  22. return ret
  23. }
  24. else {
  25. console.error("path:" + path + "not found")
  26. return false
  27. }
  28. }
  29. readEntryFile()
  30. module.exports = readEntryFile