check-vue-template.js 1011 B

1234567891011121314151617181920212223242526272829303132
  1. const fs = require('fs');
  2. const path = require('path');
  3. const { compile } = require('@vue/compiler-sfc');
  4. // 读取 Vue 文件
  5. const vueFileContent = fs.readFileSync(path.resolve(__dirname, 'src/views/front/ProjectCases.vue'), 'utf8');
  6. try {
  7. // 编译 SFC 文件
  8. const result = compile(vueFileContent);
  9. if (result.errors.length > 0) {
  10. console.error('Vue 模板编译错误:');
  11. result.errors.forEach(error => {
  12. console.error(`错误在 ${error.loc.start.line}:${error.loc.start.column} - ${error.message}`);
  13. });
  14. }
  15. if (result.warnings.length > 0) {
  16. console.warn('Vue 模板编译警告:');
  17. result.warnings.forEach(warning => {
  18. console.warn(`警告在 ${warning.loc.start.line}:${warning.loc.start.column} - ${warning.message}`);
  19. });
  20. }
  21. if (result.errors.length === 0) {
  22. console.log('Vue 模板编译成功');
  23. }
  24. } catch (error) {
  25. console.error('Vue 模板编译失败:', error);
  26. }