You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 3. Create a `gulpfile.js` at the root of your project:
29
19
30
-
## Plugin List
20
+
```javascript
21
+
/*
22
+
This is an EXAMPLE gulpfile.js
23
+
You'll want to change it to match your project.
24
+
Find plugins at https://npmjs.org/browse/keyword/gulpplugin
25
+
*/
26
+
var gulp =require('gulp');
27
+
var uglify =require('gulp-uglify');
31
28
32
-
You can view a list of plugins by going to [this npm search](https://npmjs.org/search?q=gulpplugin).
29
+
gulp.task('scripts', function() {
30
+
// Minify and copy all JavaScript (except vendor scripts)
31
+
gulp.src(['client/js/**/*.js'])
32
+
.pipe(uglify())
33
+
.pipe(gulp.dest('build/js'));
33
34
34
-
## Usage
35
+
// Copy vendor files
36
+
gulp.src('client/js/vendor/**')
37
+
.pipe(gulp.dest('build/js/vendor'));
38
+
});
35
39
36
-
This code would go in your `Gulpfile.js` (case insensitive) at the root of your project. For more information on how to use other languages check the [compilers](#compilers) section.
Takes a glob and represents a file structure. Can be piped to plugins. You can specify a single glob or an array of globs (see docs). All options are passed directly through to [glob-stream](https://github.com/wearefractal/glob-stream). See the [glob-stream documentation](https://github.com/wearefractal/glob-stream) for more information.
91
+
Takes a glob and represents a file structure. Can be piped to plugins. You can specify a single glob or an array of globs (see docs). All options are passed directly through to [glob-stream]. See the [glob-stream documentation] for more information.
102
92
103
93
```javascript
104
-
gulp.src("./client/templates/*.jade")
94
+
gulp.src('./client/templates/*.jade')
105
95
.pipe(jade())
106
96
.pipe(minify())
107
-
.pipe(gulp.dest("./public/minified_templates"));
97
+
.pipe(gulp.dest('./build/minified_templates'));
108
98
```
109
99
110
-
##### Options
100
+
#### options.buffer
101
+
Type: `Boolean`
102
+
Default: `true`
103
+
104
+
Setting this to `false` will return `file.contents` as a stream and not buffer files. This may not be supported by many plugins.
111
105
112
-
`buffer: false` will return file.content as a stream and not buffer files. This may not be supported by many plugins.
106
+
#### options.read
107
+
Type: `Boolean`
108
+
Default: `true`
113
109
114
-
`read: false` will return file.content as null and not read the file at all.
110
+
Setting this to `false` will return `file.contents` as null and not read the file at all.
115
111
116
-
### gulp.dest(path[, opt])
112
+
### gulp.dest(path[, options])
117
113
118
114
Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
119
115
120
116
```javascript
121
-
gulp.src("./client/templates/*.jade")
122
-
.pipe(jade())
123
-
.pipe(gulp.dest("./public/templates"))
124
-
.pipe(minify())
125
-
.pipe(gulp.dest("./public/minified_templates"));
117
+
gulp.src('./client/templates/*.jade')
118
+
.pipe(jade())
119
+
.pipe(gulp.dest('./build/templates'))
120
+
.pipe(minify())
121
+
.pipe(gulp.dest('./build/minified_templates'));
126
122
```
127
123
128
124
### gulp.task(name[, deps], fn)
129
125
130
126
Tasks that you want to run from the command line should not have spaces in them.
131
127
132
-
The task system is [Orchestrator](https://github.com/robrich/orchestrator) so check there for more detailed information.
128
+
The task system is [Orchestrator] so check there for more detailed information.
133
129
134
130
```javascript
135
-
gulp.task('somename', function(){
136
-
//do stuff
131
+
gulp.task('somename', function(){
132
+
//Do stuff
137
133
});
138
134
```
139
135
140
-
#####Task dependencies
136
+
#### Task dependencies
141
137
142
138
This lets you specify tasks to be executed and completed before your task will run.
If the dependencies are asynchronous it is not guaranteed that they will finish before `'somename'` is executed. To ensure they are completely finished, you need to make sure the dependency tasks have asynchronous support through one of the methods outlined below. The most simple method is to return the stream. By returning the stream, Orchestrator is able to listen for the end event and only run `'somename'` once each dependencies' stream end event has been emitted. You can also use callbacks or promises to do your own cool stuff.
gulp.env is an optimist arguments object. Running `gulp test dostuff --production` will yield `{_:["test","dostuff"],production:true}`. Plugins don't use this.
220
216
221
-
## gulp cli
217
+
218
+
## gulp CLI
222
219
223
220
### Tasks
224
221
225
-
Tasks can be executed by running `gulp <taskname><othertask><somethingelse>`. Just running `gulp` will execute the task you registered called `default`. If there is no `default` task gulp will error.
222
+
Tasks can be executed by running `gulp <task><othertask>`. Just running `gulp` will execute the task you registered called `default`. If there is no `default` task gulp will error.
This is a simple plugin that adds a header to the beginning of each file. It takes one argument (a string). Let's call it `gulp-header`. I recommend event-stream as a utility for creating these plugins.
235
+
## Write your own gulp plugins
241
236
242
-
#### Code
237
+
See the [Writing a gulp plugin] wiki page for guidelines and an example to get you started.
243
238
244
-
```javascript
245
-
var es =require('event-stream');
246
-
247
-
module.exports=function(header){
248
-
// check our options
249
-
if (!header) thrownewError("header option missing");
See [the wiki][wiki] for more information and [the FAQ][FAQ] for more answers to common questions.
260
243
261
-
// return a stream
262
-
returnes.map(modifyContents);
263
-
}
264
-
```
265
-
266
-
#### Usage
267
-
268
-
```javascript
269
-
var gulp =require('gulp');
270
-
var header =require('gulp-header');
271
-
272
-
// Add a copyright header to each file
273
-
gulp.src('./client/scripts/*.js')
274
-
.pipe(header('// This file is copyrighted'))
275
-
.pipe(gulp.dest("./public/scripts/"))
276
-
```
277
-
278
-
## Plugin Guidelines
279
-
280
-
A gulp plugin is exclusively something that deals with file streams. If your library is not for streaming files but is still made for use with gulp, just tag it as `gulpfriendly` instead of `gulpplugin`.
281
-
282
-
1. file.contents should always go out the same way it came in
283
-
- Respect buffered, streaming, and non-read files as well as folders!
284
-
1. Do not pass the file object downstream until you are done with it
285
-
1. Make use of the gulp-util library. Templating, CLI colors, logging. Do you need to change a file's extension or do some tedious fs crap? Try looking there first and add it if it doesn't exist
286
-
1. Remember: Your plugin should only do one thing! It should not have a complex config object that makes it do multiple things. It should not concat and add headers/footers. This is not grunt. Keep it simple.
287
-
1. Do not throw errors. Emit them from the stream (or pass them to the callback if using event-stream's .map).
288
-
1. Add "gulpplugin" as a keyword in your package.json so you show up on our search
289
-
290
-
If you don't follow these guidelines and somebody notices your plugin will be shitlisted from the ecosystem.
291
244
292
245
## LICENSE
293
246
@@ -317,3 +270,18 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 commit comments