Based on https://github.com/coderiver/generator-man
Clone this repo and then in command line type:
npm install
oryarn
- install all dependenciesgulp
- run dev-server and let magic happen, orgulp build
- build project from sources
To run separate task type in command line gulp [task_name]
.
Almost all tasks also have watch mode - gulp [task_name]:watch
, but you don't need to use it directly.
Task name | Description |
---|---|
default |
will start all tasks required by project in dev mode: initial build, watch files, run server with livereload |
build:dev |
build dev version of project (without code optimizations) |
build |
build production-ready project (with code optimizations) |
Task name | Description |
---|---|
sass |
compile .sass/.scss to .css. We also use postcss, so feel free to include other awesome postcss plugins when needed |
webpack |
compile .js sources into bundle file |
copy |
copy common files from ./src path to ./build path |
nunjucks |
compile Mozilla's awesome nunjucks templates |
svgo |
optimize svg files with svgo |
svgicons |
take .svg sources from ./icons clean and create .html files in ./templates/partials/icons to use it inline |
sprite-png |
create png sprites |
server |
run dev-server powered by BrowserSync |
clean |
remove ./build folder |
list-pages |
create index file with links to all project pages |
All available tasks are placed in a folder ./gulp/tasks
as separate *.js files. Usually, file name = task name.
We have several useful flags.
gulp --open
orgulp server --open
- run dev server and then open preview in browsergulp [task_name] --prod
orgulp [task_name] --production
- run task in production mode. Some of the tasks (like, sass or js compilation) have additional settings for production mode (such as code minification), so with this flag you can force production mode.gulp build
uses this mode by default.
If you need a multilanguage version of project, you can create folder languages
in src
directory, then create subdirectories with data files.
Each subdirectory requires global.json
file, with some general data. Optionaly, you can add other json
files, with data to specific page. The names of the files has to be equivalent to project pages names.
Data from json
files can be used in page template as variables.
In build folder would be generated files with different language versions. Amount of pages would be equivalent to amount of languages
folder subdirectories, filenames would have suffix, equivalent to subdirection name.
.
├── ...
├── src
│ ├── languages
│ │ ├── en
│ │ │ ├── global.json
│ │ │ ├── page.json
│ │ ├── ru
│ │ │ ├── global.json
│ │ │ ├── page.json
│ ├── templates
│ │ ├── page.html
│ │ └── ...
│ └── ...
└── ...
.
├── ...
├── build
│ ├── page-en.html
│ ├── page-ru.html
└── ...
// languages/en folder
// global.json
{
"sitename": "My awesome site"
}
// page.json
{
"title": "Main page"
}
// languages/ru folder
// global.json
{
"sitename": "Мой крутой сайт"
}
// page.json
{
"title": "Главная страница"
}
<!-- Development -->
<!-- templates/page.html -->
<h1>{{ sitename }}</h1>
<h2>{{ title }}</h2>
<!-- Generated -->
<!-- build/page-en.html -->
<h1>My awesome site</h1>
<h2>Main page</h2>
<!-- build/page-ru.html -->
<h1>Мой крутой сайт</h1>
<h2>Главная страница</h2>
You can also use npm scripts:
npm run start
- same asgulp default
.npm run build
- same asgulp build
.npm run ghpages
to push only./build
folder to gh-pages branch on github (very useful for previews).