Gulp Webpack Boilerplate
A modern JavaScript starter toolkit for web-development using Gulp task runner and Webpack bundler.
Ideal for fast building static HTML sites or templates. It speeds up the proccess of delevelopment,testing and deploy in a front-end project. Also it can be extended in a simple way when projectrequire some extra functionality provided by thirdparty packages.
All the tasks are done via Gulp. Webpack is just used for Javascript (especially for ES6Import/Export as Gulp can't do it in a proper way) and not for rest because it's a little bitoverhed to translate all static assets and styles through js using Webpack.
Feature | Description |
---|---|
Javascript | Full support of javascript latest features using Babel loader and Webpack. Also, there is a lot of code optimization while building in production mode. |
HTML | Pug templates provide an opportunity to make a better structure and code readability and then compiling it to HTML. |
Styles | Stylus support with compiling to css and doing minification with concatenation. |
Autoprefixier | Parse CSS and add vendor prefixes(-wbkit, -moz, -o, -ms) to rules in production build. |
Sourcemaps | Css and js source maps in development mode. |
Bootstrap | You can specify what part of Bootstrap do you need and then compile it to get the low size files. |
Live Reload | Automatic reloading of the browser on code modification and cross-platform syncing of all actions between connected devices. This depends on Gulp-watch, Webpack-watch, BrowserSync. |
Google Fonts | Auto-downloads Google fonts specified in fonts list then generates css with them and finally moves them to the build dir. |
Images | Compressing images to desired quality and size through Mozjpeg or Guetzli. |
Hashed names | File names contain smart hashes in production mode. Hash will change on file modifications. This helps to avoid browser long term caching. |
Code linting | Eslint checks js code according to AirBnb rules and notify if something wrong. |
Code formatting | Prettier auto-formats js code that doesn't satisfy Eslint styles rules. |
Cached files | Gulp tasks configured to process only new files in development mode. |
Error notifier | You get a desktop notification when errors occur. |
├── dist/ # Static version of the website
│ ├── css/ # Folder for concatenated css file
│ ├── fonts/ # All fonts files
│ ├── img/ # Images
│ ├── js/ # Folder for bundle js file
│ └── index.html # Can be any page and more than one
├── src/ # Source files
│ ├── fonts/ # Fonts
│ │ └── fonts.list # Google Fonts config
│ ├── img/ # Site images
│ ├── js/ # Javascript files
│ │ ├── bootstrap.js # Uncomment module that you need
│ │ ├── entry.js # Webpack entry point
│ │ └── main.js # All user scripts
│ ├── styles/ # Styles
│ │ ├── bootstrap/ # Bootstrap sass config
│ │ │ ├── bootstrap.scss # Uncomment module that you need
│ │ │ └── _variables.scss # Change what you want
│ │ └── main.styl # Main stylesheet file
│ ├── templates/ # Site templates (Pug)
│ │ ├── pages/ # Pug only looks for this dir
│ │ │ └── index.pug # You can create any amount of pages in this dir
│ │ ├── navigation.pug # Site navigation
│ │ ├── header.pug # Site header
│ │ ├── footer.pug # Site footer
│ │ └── layout.pug # Main layout
│ └── vendor/ # Appears if CUSTOM_SOURCE options specified or fonts enabled.
│ ├── bootstrap/ # Change source files to whatever you want
│ └── googleFonts/ # Storage for downloaded fonts
├── temp/ # Temporary folder
│ └── manifest/ # Manifests for the production build
│ └── rev-images.json # Hashed images names
├── .babelrc # Babel presets for latest js features
├── .eslintrc.js # ESLint config
├── .gitignore # List of files ignored by git
├── .prettierrc # Prettier formatter config
├── gulpfile.babel.js # Gulpfile config and tasks
├── license # Project license
├── package.json # Node.js dependencies and scripts
└── readme.md # Description of the project
sudo apt update
sudo apt install build-essential ; sudo apt install libssl-dev
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
source ~/.bashrc
nvm install node
nvm use node
sudo apt install yarn
ornvm install --latest-npm
yarn run
or npm start
:
yarn add global
ornpm install --global gulp
cd somedirectory
git clone https://github.com/noth8/gulp-webpack-boilerplate.git
cd gulp-webpack-boilerplate
yarn install
or npm install
name | Description |
---|---|
yarn run dev |
Build in development mode |
yarn dev |
Same as yarn run dev |
yarn run prod |
Build in production mode |
yarn prod |
Same as yarn run prod |
name | Description |
---|---|
npm run dev |
Build in development mode |
npm run prod |
Build in production mode |
gulpfile.babel.js
name | default | true | false |
---|---|---|---|
GOOGLE_FONTS_ENABLED | true | Gulp downloads fonts listed in fonts.list and copies them to dist dir. |
- |
BOOTSTRAP_ENABLED | true | Specify what you need in : bootstrap.js , bootstrap.scss , _variables.scss and webpack will take it from bootstrap source and add it to bundle. |
You can also use default bootstrap by specifying import 'bootstrap' in entry.js |
BOOTSTRAP_CUSTOM_SOURCE | true | Give you a copy of bootstrap source if you want to make some changes directly. | Using bootstrap from node_modules/ |
AUTOPREFIXER_BROWSER_LIST | last 2 versions | browsers versions that automatically gets properties specific to them (-ms , -moz , -webkit ) |
- |
IMAGE_ENCODER_GUETZLI | false | Uses Guetzli encoder for build in production mode. | Uses MozJPEG encoder for build in production mode. |
IMAGE_COMPRESSION_RATE | 84 | Compression quality, in range 0 (worst) to 100 (perfect). | - |
General :
gulp - The streaming build system.
Purpose : automated development process by running tasks.
webpack - is a bundler for javascript. Packs many modules into one or a few bundled assets.
Purpose : proper js bundling what gulp doesn't do.
bootstrap - is an open source framework for developing with HTML, CSS, and JS.
Purpose : responsive grid on web and mobile.
jquery - is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation.
Purpose : for custom code and also for bootstrap dependency.
popper.js - A popper is an element on the screen which "pops out" from the natural flow of your application.
Purpose : bootstrap dependency.
gulp-google-webfonts - a plugin to download Google webfonts and generate a stylesheet for them.
Purpose : automate the process of using google webfonts just specifying them in one file(fonts.list).
gulp-load-plugins - loads gulp plugins from package dependencies and attaches them to the specified object.
Purpose : imports google-webfonts when they are needed (alternative to "require" with lazy loading).
gulp-if - a ternary plugin: conditionally control the flow of vinyl objects.
Purpose : helps to run plugins according to development or production mode specified.
gulp-plumber - prevents pipe breaking caused by errors from gulp plugins.
Purpose : catch errors and send them to the node-notifier.
gulplog - logger for gulp and gulp plugins
Purpose : pass to webpack errorHandler and print info if errors occur.
node-notifier - a Node.js module for sending notifications on native Mac, Windows, and Linux.
Purpose : displays errors with platform-native notifications.
gulp-pug - is a plugin for compiling Pug templates.
Purpose : translate pug files into html.
through2 - is a tiny wrapper around Node.js streams. Allows writing gulp plugin.
Purpose : pass file name from stream to pug for navigation based on location.
gulp-sass - is a wrapper around node-sass.
Purpose : compiles .scss files into css.
node-sass - is a library that provides a binding for Node.js to LibSass.
Purpose : it's needed for gulp-sass.
gulp-stylus - is a wrapper around stylus.
Purpose : compiles .styl files into css.
stylus - providing an efficient and dynamic way to generate CSS
Purpose : it's needed for gulp-stylus.
merge2 - Merge multiple streams into one stream in sequence or parallel.
Purpose : for skipping Bootstrap and Google fonts from merging when they are disabled.
gulp-inject - ф javascript, stylesheet, and web component injection plugin.
Purpose : injects css and js files into html files by replacing special tags specified in pug files.
gulp-concat - Streaming concatenation middleware for gulp
Purpose : merge css files into one.
stream-combiner2 - Turn a pipeline into a single stream.
Purpose : less code for better readability.
@babel/core - the core functionality of Babel.
Purpose : babel-loader dependency.
@babel/register - is a require hook, that will bind node’s require method and automatically transpile the file on the fly.
Purpose : gulp.babel.js for es6 features.
@babel/preset-env - is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This Needs for webpack babel-loader.
Purpose : babel-loader configuration.
babel-loader - Babel loader for webpack
Purpose : transforms Javascript code from new standards to previous for old browser support.
babel-eslint - a wrapper for Babel's parser used for ESLint
Purpose : custom parser specified in eslintrc.js
eslint - ESLint is an open source JavaScript linting utility.
Purpose : static javascript code analysis using specified rules.
eslint-config-airbnb-base - base(without react) AirBnb list of rules.
Purpose : just because of the most popular and nice javascript style guide
eslint-plugin-import - ESLint plugin with rules that helps validate proper imports.
Purpose : checks es6 imports.
Production :
del - delete files and folders using globs
Purpose : deletes build dir before other tasks run.
gulp-autoprefixer - PostCSS plugin to parse CSS and add vendor prefixes to CSS rules using values from Can I Use.
Purpose : automatically adds browser's specific prefixes like '-moz', '-webkit-', '-ms'.
gulp-clean-css - clean-css is a fast and efficient CSS optimizer.
Purpose : minify css files.
gulp-imagemin - is an image compressor which is built around plugins like mozjpeg and others.
Purpose : minifies jpeg images with mozjpeg vs guetzli.
imagemin-guetzli - imagemin plugin for guetzli.
Purpose : Guetzli-generated images are typically 20-30% smaller than others.
imagemin-mozjpeg - Imagemin plugin for mozjpeg
Purpose : Mozjpeg-generated images are larger than Guetzli-generated but Mozjpeg is much faster.
gulp-rev - appending content hash to filenames.
Purpose : helps to get rid of browser long term caching.
gulp-rev-replace - rewrite occurrences of filenames which have been renamed by gulp-rev.
Purpose : replaces names in links to the images specified in html and css files from original to hashed using manifest file generated by gulp-rev.
Development :
browser-sync - keep multiple browsers & devices in sync.
Purpose : automatically reloads content on each saves on all connected devices and also catches all actions occurred in one of them and relays to others.
gulp-sourcemaps - provides sourcemap support for other plugins.
Purpose : may show original css code locations before merging into one css.
gulp-cached - this keeps an in-memory cache of files (and their contents) that have passed through it.
Purpose : caches styles between incremental builds.
gulp-remember - is a plugin that remembers and recalls files passed through it.
Purpose : passes files to gulp-concat that were thrown back by gulp-cashed.
gulp-newer - a plugin for passing through only those source files that are newer than corresponding destination files.
Purpose : processes the same fonts and images only once between incremental builds.
Guetzli is a JPEG encoder that aims for excellent compression density at the high visual quality. Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg. Guetzli generates only sequential (non-progressive) JPEGs due to faster decompression speeds they offer.
it uses a large amount of memory. You should provide 300MB of memory per 1MPix of the input image.
Guetzli uses a significant amount of CPU time. You should count on using about 1 minute of CPU per 1MPix of an input image.
Guetzli assumes that input is in sRGB profile with a gamma of 2.2. Guetzli will ignore any color-profile metadata in the image.
Guetzli is designed to work on high-quality images (e.g. that haven't been already compressed with other JPEG encoders). While it will work on other images too, results will be poorer. You can try compressing an enclosed sample high-quality image.
Guetzli converts PNG/JPG to JPG. When using this plugin or guetzli-bin CLI, the original filename+ext is used as the output, although the image format has changed. You have to rename the file with the correct file extension (JPG) yourself afterward.
gulp webpack 定位 基于任务流的自动化打包工具 模块化打包工具 优点 易于学习和理解, 适合多页面应用开发 可以模块化的打包任何资源,适配任何模块系统,适合SPA单页应用的开发 缺点 不太适合单页或者自定义模块的开发 学习成本低,配置复杂,通过babel编译后的js代码打包后体积过大
这里先来一个大方向的说明,gulp是流程化的,webpack是模块化的,webpack有个缺点就是他需要把所有的import全部引入,这就意味着不方便处理less文件,所以我们经常是使用webpack来处理js进行es6的解析和react的jsx解析,然后用gulp来设置一个task来命令webpack进行js打包(label等依赖包),而gulp完成less的解析和css的压缩(csso包)和c
1、webpack Webpack 是一个模块打包工具。它将一堆文件中的每个文件都作为一个模块,找出他们的依赖关系,将它们打包为可部署的静态资源。 2、grunt/gulp 自动化构建工具,就是用来代替手工执行机械重复的事情,解放我们的双手的。 例如,项目使用 CoffeeScript/ES6代替Javascript,但浏览器对这些语言是不支持或者支持得不完整的,要让它在浏览器里运行起来就要执行以
1、Grunt Grunt 的出现早于 Gulp,Gulp 是后起之秀。他们本质都是通过 JavaScript 语法实现了 shell script 命令的一些功能。比如利用 jshint 插件实现 JavaScript 代码格式检查这一功能。早期需要手动在命令行中输入 jshint test.js,而 Grunt 则通过 Gruntfile.js 进行配置 // Gruntfile.js
什么是前端工程化? 随着前端行业的发展,现在的前端越来越像一个大工程,从几年前前端的webPage模式(写写单页面,jquery,使用几个插件网页就建成),到现在的webapp模式(一个完整的app软件开发),前端可谓是经历了翻天覆地的大变化。随着web业务的日益复杂化和多元化,以前以webpage模式为主的开发模式,已经不能够满足现在的需求,那么如何做到更效率更自动化的前端软件开发,前端工程化应
三者都是前端构建工具,grunt和gulp在早期比较流行,现在webpack相对来说比较主流,不过一些轻量化的任务还是会用gulp来处理,比如单独打包CSS文件等。 grunt和gulp是基于任务和流(Task、Stream)的。类似jQuery,找到一个(或一类)文件,对其做一系列链式操作,更新流上的数据, 整条链式操作构成了一个任务,多个任务就构成了整个web的构建流程。 webpack是基于
一.webpack与grunt、gulp的不同 三者都是前端构建工具,grunt和gulp在早期比较流行,现在webpack相对来说比较主流,不过轻量化的任务还是会用gulp来处理,比如单独打包CSS文件等 grunt和gulp是基于任务和流(Task、Stream)的,类似jQuery,找到一个(或一类) 文件,对其做一系列链式操作,更新流上的数据,整条链式操作构成一个任务,,多个任务就构成了整
一、Loader 1.loader的作用: webpack 只能直接处理 javascript 格式的代码。任何非 js 文件都必须被预先处理转换为 js 代码,才可以参与打包。loader(加载器)就是这样一个代码转换器。 2.loader的工作原理: 它由 webpack 的 `loader runner` 执行调用,接收原始资源数据作为参数(当多个加载器联合使用时,上一个loader的结果会
Gulp与Webpack gulp是什么? 是工具链 是构造工具 旨在规范前端开发流程 可以配合各种插件做js压缩 css压缩 less编译 替代手动实现自动化工作 基于node强大的流(stream)能力,gulp在构建过程中并不把文件立即写入磁盘,从而提高了构建速度 gulp为高级编译程序 可用组件很多 通过一系列插件将原本复杂繁琐的任务自动化 并不能将你的css等非js资源模块化 gulp是
Gulp和Webpack的基本区别: gulp可以进行js,html,css,img的压缩打包,是自动化构建工具,可以将多个js文件或是css压缩成一个文件,并且可以压缩为一行,以此来减少文件体积,加快请求速度和减少请求次数;并且gulp有task定义处理事务,从而构建整体流程,它是基于流的自动化构建工具。 Webpack是前端构建工具,实现了模块化开发和文件处理。他的思想就是“万物皆为模块”,它
gulp 是自动化构建工具,可以配合各种插件做 js 压缩、css 压缩、less 编译、代码检查等,替代手工实现自动化工作: 构建工具 自动化 提高效率用 webpack是文件打包工具,可以把项目的各种 js、css文件等打包合并成一个或多个文件,主要用于模块化方案,预编译模块的方案 打包工具 模块化识别 编译模块化代码方案用 Gulp应该和Grunt比较。Gulp / Grunt 是一种工具
1.gulp使用 gulp 是基于 Node.js 的一个前端自动化构建工具,主要用来设定程序自动处理静态资源的工作,您可以使用它构建自动化工作流程(前端集成开发环境),在 Web 前端开发工作中有很多“重复工作”,例如:网页自动刷新,CSS预处理,代码检测,图片压缩等功能,编写gulp配置,可以让gulp自动执行这些“重复工作”,只需要简单的命令行就可以全部完成。使用它,可以简化工作,让你把重点
webpack和gulp的区别? gulp是工具链,构建工具,可以进行css,js的文件压缩,less,sass的编译,替代一些手工实现自动化。 webpack是打包工具,可以把项目中的css,js文件合并打包成一个或多个文件,可以进行模块化。 gulp: 1.构建项目的工具 2.模块化 3.提高工作效率 webpack: 1.打包工具 2.模块化识别 3.编译模块工具
Gulp 不具备任何具体功能,完全自主,自定义性强 Tasks Runner 需要开发者自己实现各种功能 对 Node.js 储备要求高 强调任务的概念,Gulp 本身实际上是一个任务调度工具(tasks runner) 通俗点说:Gulp 就是你想干什么就干什么~ Webpack 从模块打包出发,通过插件实现一部分 Web 项目的自动化任务 模块化打包功能开箱即用,相对门槛更低 主要应对 SPA
常有人拿gulp与webpack来比较,知道这两个构建工具功能上有重叠的地方,可单用,也可一起用,但本质的区别就没有那么清晰。 gulp gulp强调的是前端开发的工作流程,我们可以通过配置一系列的task,定义task处理的事务(例如文件压缩合并、雪碧图、启动server、版本控制等),然后定义执行顺序,来让gulp执行这些task,从而构建项目的整个前端开发流程。 PS:简单说就一个Task
grunt/gulp的核心是Task 我们可以配置一系列的task,并且定义task要处理的事务(例如es6,ts转化,图片压缩,scss转成css) 之后让grunt/gulp来依次执行这些task,而且让整个流程自动化。 所以grunt/gulp也被称为前端自动化任务管理工具 来看一个gulp的task 下面的task就是将src文件下所有的js文件转换成es5 的语法 并最终输出到dist文
原文地址 gulp gulp强调的是前端开发的工作流程,我们可以通过配置一系列的task,定义task处理的事务(例如文件压缩合并、雪碧图、启动server、版本控制等),然后定义执行顺序,来让gulp执行这些task,从而构建项目的整个前端开发流程。 PS:简单说就一个Task Runner webpack webpack是一个前端模块化方案,更侧重模块打包,我们可以把开发中的所有资源(图片、j
�� Gulp Webpack Starter Gulp Webpack Starter - fast and simple web development toolkit.It uses Gulp task runner and Webpack bundler.The starter perfectly fits building static HTML templatesor speeding
项目介绍 采用vue-cli 构建初始项目目录 使用vue、vue-router、express、webpack、gulp、Element-ui构建项目开发环境 前端采用Vue、Element-ui搭建页面以及数据处理,后端采用express完成增删改查的restful API 页面为电影列表页以及电影详情页 目录及文件的改动,均含详细备注 config/index.js 中设置了请求端口代理,能
本文向大家介绍webpack 和 gulp 对比相关面试题,主要包含被问及webpack 和 gulp 对比时的应答技巧和注意事项,需要的朋友参考一下 Gulp就是为了规范前端开发流程,实现前后端分离、模块化开发、版本控制、文件合并与 压缩、mock数据等功能的一个前端自动化构建工具。说的形象点,“Gulp就像是一个产品的 流水线,整个产品从无到有,都要受流水线的控制,在流水线上我们可以对产品进行
WordPress Gulp and Webpack starter theme Under the hood ES6 for JavaScript (transpiling with Babel and linting with ESLint) SASS preprocessor for CSS with SASS Guidelines Bootstrap 5 as CSS framework
我似乎无法找出正确的方法来加载相互依赖的第三方库。我将TypeScript和Gulp与Webpack或SystemJS一起用于我的模块加载器,在本例中,这两个模块都有类似的错误。如果我只使用jQuery,我的应用程序代码可以工作,但是如果我尝试使用jQuery插件,比如jQuery验证,我会从Webpack和SystemJS中得到类似的错误,关于jQuery未定义。 这两种设置都有很多配置,我将在
本文向大家介绍webpack和gulp区别(模块化与流的区别)?相关面试题,主要包含被问及webpack和gulp区别(模块化与流的区别)?时的应答技巧和注意事项,需要的朋友参考一下 gulp强调的是前端开发的工作流程,我们可以通过配置一系列的task,定义task处理的事务(例如文件压缩合并、雪碧图、启动server、版本控制等),然后定义执行顺序,来让gulp执行这些task,从而构建项目的整