首页 > 其他 > 详细

gulp简单用法和问题总结

时间:2020-05-26 15:49:54      阅读:232      评论:0      收藏:0      [点我收藏+]

1需要先安装gulp命令行工具

npm install --global gulp-cli

2 gulp的使用,作为开发依赖包

npm install --save-dev gulp

注意: 1 安装gulp时项目name不能是gulp和包同名

         2 gulp3和gulp4的写法不同,在安装gulp v=4.*版本的使用gulp3的写法会报如下错误错;

assert.js:339
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Task function must be specified
    ...
    at require (internal/modules/cjs/helpers.js:25:18)

  3 在项目开始时目录文件为空,清理目录文件会报错,解决方法:可以新建一个空的dist文件夹

$ gulp build
[14:22:49] Using gulpfile D:\myself\gulpt\gulpfile.js
[14:22:49] Starting ‘build‘...
[14:22:49] Starting ‘cleanD‘...
[14:22:49] ‘cleanD‘ errored after 22 ms
[14:22:49] Error: File not found with singular glob: D:/myself/gulpt/dist/ (if this was purposeful, use `allowEmpty` option)
    ...
[14:22:49] ‘build‘ errored after 24 ms

  4 在进行js压缩时,遇到了es6的语法,会不支持而报错;

$ gulp build
[14:30:13] Using gulpfile D:\myself\gulpt\gulpfile.js
[14:30:13] Starting ‘build‘...
[14:30:13] Starting ‘cleanD‘...
[14:30:13] Finished ‘cleanD‘ after 31 ms
[14:30:13] Starting ‘css‘...
[14:30:13] Starting ‘javascript‘...
[14:30:13] Starting ‘html‘...
[14:30:13] ‘javascript‘ errored after 92 ms
[14:30:13] GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected character ‘`‘
File: D:\myself\gulpt\js\detail.js

  解决方案:1安装npm install  --save-dev babel-core  gulp-babel 

注意:1 安装完babel-core之后运行会报错Error: Cannot find module ‘@babel/core‘  ,故可以直接安装@babel/core,不用使用babel-core(两者的区别在于@babel/core是babel-core的新版本)

           2安装gulp-babel需要依赖babel-preset-es2015 

[15:06:22] ‘javascript‘ errored after 77 ms
[15:06:22] Error in plugin "gulp-babel"
Message:
    Cannot find module ‘babel-preset-es2015‘ from ‘D:\myself\gulpt‘
[15:06:22] ‘build‘ errored after 79 ms

  3 都安装完成后还是报错如下:

‘javascript‘ errored after 644 ms
[15:10:09] Error in plugin "gulp-babel"
Message:
    Plugin/Preset files are not allowed to export objects, only functions. In D:\myself\gulpt\node_modules\babel-preset-es2015\lib\index.js
[15:10:09] ‘build‘ errored after 648 ms

  

安装各个需要的插件

gulp简单用法和问题总结

原文:https://www.cnblogs.com/xhliang/p/12958312.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!