在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sf-wdi-gaia/gulp开源软件地址(OpenSource Url):https://github.com/sf-wdi-gaia/gulp开源编程语言(OpenSource Language):JavaScript 88.6%开源软件介绍(OpenSource Introduction):GulpWhy is this important?This workshop is important because: Gulp is a useful tool for automating tasks in order to increase productivity. Today we'll specifically use it mostly for transpiling ES6 to ES5 and Sass into CSS. What are the objectives?After this workshop, developers will be able to:
Where should we be now?Before this workshop, developers should already be able to:
Introducing Gulp
Installing Gulp
No gulpfile found Oops, we ran into an error. Gulp requires that we store our tasks in a Using gulpfile ~/path/to/gulpfile.js
Task 'default' is not in your gulpfile
Please check the documentation for proper gulpfile formatting Another error! Ok, let's solve this problem by defining a Gulp task. Defining a Gulp Task
In our First (Default) TaskAfter declaring our var gulp = require('gulp');
//define a task with the name of 'default'
// and a callback to perform when the task is ran
gulp.task('default', function() {
console.log('I am the default task. Hear me roar');
}); In your terminal, run Starting 'default'...
I am the default task. Hear me roar
Finished 'default' after 144 μs Compiling SassCreate a new directory npm init
npm install --save-dev gulp gulp-sass //gulpfile.js
var gulp = require('gulp');
var sass = require('gulp-sass'); Define a gulp.task('styles', function() {
gulp.src('sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css/'));
}); Create a Run Lastly let's add the task we just created to gulp's To do this, at the bottom of your file add: gulp.task('default',function() {
gulp.watch('sass/**/*.scss',['styles']);
}); Compiling ES6We've yet to talk about ES6, aka ECMAScript 2015, but it's the next iteration of JavaScript so let's get a taste for it. It's nice to write in, but not supported everywhere yet. Let's write some ES6 code and compile it to ES5, which is universally supported. Create a new directory somewhere called Require all the modules we'll be using. npm init
npm install --save-dev gulp gulp-babel babel-preset-es2015 Create a file for touch gulpfile.js Inside the file do something similar to what we did to transpile our sass. Instead now we'll be using Here we'll be creating a task called At the very bottom, just like previously, we're creating a default watch task that will execute the var gulp = require('gulp');
var babel = require('gulp-babel');
gulp.task('scripts', function () {
return gulp.src('src/**/*.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('dist'));
});
gulp.task('default',function() {
gulp.watch('src/**/*.js',['scripts']);
});
Let's try out some ES6. Below find some working ES6 code, take a moment to look it over. What are your thoughts? // define an ES6 class called Person
class Person {
// define the method to run for each instantiation
constructor(name, age, type="person") {
this.name = name
this.age = age
this.type = type
}
// define a greet method
greet() {
return `Hi I'm ${this.name}!`
}
}
// export the Person class
module.exports = Person Run
Challenge: Can you instantiate a new person? Exciting stuff! Here's a quick look at some of the new ES6 syntax. Take a moment to review it and then try out this online quiz (open book is fine). It will introduce you to some new ES6 concepts. Feel free to jot down anything that's surprising and we'll discuss it. Feel free to try any of this fancy ES6 stuff out in your Additional Notes
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论