Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

评论:使用 gulp 压缩 JS #11

Closed
nimoc opened this issue Apr 6, 2015 · 18 comments
Closed

评论:使用 gulp 压缩 JS #11

nimoc opened this issue Apr 6, 2015 · 18 comments
Labels

Comments

@nimoc
Copy link
Owner

nimoc commented Apr 6, 2015

请在此处留下你对 使用 gulp 压缩 JS 的评论

@Gaohaoyang
Copy link

运行 gulp script 为什么有如下错误

E:\GitWorkSpace\test\gulpTest (master)
λ gulp script
[17:28:14] Local gulp not found in E:\GitWorkSpace\test\gulpTest
[17:28:14] Try running: npm install gulp

@nimoc
Copy link
Owner Author

nimoc commented Jun 19, 2015

@Gaohaoyang 请运行 gulp -v看是否出现版本提示

[17:38:39] CLI version 3.8.11
[17:38:39] Local version 3.8.11

如果没有出现请参考 https://github.com/nimojs/gulp-book/blob/master/chapter1.md#安装-gulp

@Gaohaoyang
Copy link

@nimojs 没有下面的 local 版本。你又安装了非全局的gulp?

C:\Users\admin
λ gulp -v
[17:41:44] CLI version 3.9.0

我在目录下又执行 npm install gulp 后,就成功了

E:\GitWorkSpace\test\gulpTest (master)
λ gulp -v
[17:43:28] CLI version 3.9.0
[17:43:29] Local version 3.9.0

但是文件目录变为中 node_modules 添加了 gulp

@nimoc
Copy link
Owner Author

nimoc commented Jun 19, 2015

跟 node 的包机制有关

// 获取 gulp
var gulp = require('gulp')

如果你全局没有 gulp 或者 项目中没有 node_modules gulp 就会导致无法获取模块

@Gaohaoyang
Copy link

恩,那安装了全局的 gulp 为什么在这个工程里是无法访问到的?

@Gaohaoyang
Copy link

http://stackoverflow.com/a/29965514
已找到解决方案了。

执行 npm link gulp 将全局 gulp 连接到这个目录下就好了。

E:\GitWorkSpace\test\gulpTest (master)
λ npm link gulp
E:\GitWorkSpace\test\gulpTest\node_modules\gulp -> C:\Users\admin\AppData\Roaming\npm\node_modules\gulp

@tl390
Copy link

tl390 commented Aug 8, 2015

我和 @Gaohaoyang 的问题是一样的,但是按照他的解决方法 执行 npm link gulp 后报这个错

$ gulp script
[12:55:28] Using gulpfile f:\wamp\www\gulp_tl\chapter2\gulpfile.js
[12:55:28] Task 'script' is not in your gulpfile
[12:55:28] Please check the documentation for proper gulpfile formatting

@nimoc
Copy link
Owner Author

nimoc commented Aug 9, 2015

@TI390
先试试将文件放在 C 盘并运行
试试将 这里的 gulpfile.js 文件下载到本地先试试 https://github.com/nimojs/gulp-book/tree/master/demo/chapter2
或者先直接试试

gulp

@nimoc
Copy link
Owner Author

nimoc commented Aug 9, 2015

恩,那安装了全局的 gulp 为什么在这个工程里是无法访问到的?

看了下你存放的目录结构
E:\GitWorkSpace\test\gulpTest\node_modules\gulp -> C:\Users\admin\AppData\Roaming\npm\node_modules\gulp

你的 node 的包全局安装是在 c 盘的,根据 node 的 module 查找方式,他是无法跨盘符寻找的。所以用 npm link 可以强制执行包的路径

@tl390
Copy link

tl390 commented Aug 9, 2015

@nimojs
在当前目录再安装一下NPM包,解决了问题

@nfer
Copy link

nfer commented Apr 6, 2016

// 使用 gulp.task('default') 定义默认任务
// 在命令行使用 gulp 启动 script 任务和 auto 任务
gulp.task('default', ['script', 'auto'])

这里default目标为什么是两个呢?只有一个auto不可以吗?实测也是OK的。所以求解这里为什么要写两个目标

@bigggge
Copy link

bigggge commented Sep 5, 2016

gulp.src('js/*.js')可以访问js文件夹下的js文件,请问如何可以访问js下所有子文件夹的js文件?

@mebtte
Copy link

mebtte commented Sep 5, 2016

访问js文件夹下所有子文件夹的js文件gulp.src('js/*/.js')

@nimoc
Copy link
Owner Author

nimoc commented Sep 5, 2016

@PanHongyi
gulp.src 用的是 glob 语法。基本上你多次测试就能掌握了。

@bigggge
Copy link

bigggge commented Sep 5, 2016

@PanHongyi 'sass//.scss'两个是什么意思,有相关资料吗?

@nimoc
Copy link
Owner Author

nimoc commented Sep 5, 2016

** 的意思是任何目录

https://github.com/isaacs/node-glob

其实只要多测试几次基本能搞定大部分需求了

@nimoc
Copy link
Owner Author

nimoc commented Sep 9, 2016

@bigggge
http://fis.baidu.com/fis3/docs/api/config-glob.html
这个glob文档不错,可以看看。

@bigggge
Copy link

bigggge commented Sep 10, 2016

@nimojs 好的,谢谢

@nimoc nimoc closed this as completed Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants