Awesome static site generator using Webpack!
- Webpack
- SASS
- PUG for templating
- ES6
- Install Node.js
Check to see if you already have Node installed. Do this by bringing up a terminal/command prompt and type node -v
. If the response shows a version at or above v0.5.x
, you are all set and can proceed to installing Yeoman. If you see an error and/or your version is too low, navigate to the Node.js website and install Node from there.
- Install Yeoman
npm install -g yo
- Install generator-yolo
npm install -g generator-yolo
-
Generating new project
Create a new folder with intended project name. open command line and navigate to the newly created folder.
Once you are in the project folder. Run the following command.
yo yolo
Generator will automatically run npm install
once the project files has been created.
Once everything is installed, you will see a project structure like below:
├── src
| ├── _data # JSON files that add data to templates
| ├── _fonts # Font files
| ├── _images # Images
| ├── _layouts # Layout structure for app
| | └── base.jade
| ├── _modules # Reusable modules
| | └── button
| | ├── button.pug
| | ├── button.js
| | └── button.scss
| ├── _styles # Global styles, mixins, variables, etc
├── _fonts.scss # Custom font entries
| | └── main.scss # Main stylesheet (import everything to this file)
| ├── _scripts # Global scripts, base classes, etc
| | └── index.js # Main bootstrap file
| ├── _fonts # Fonts (Example, will not be generated)
| ├── index.jade # Homepage template
| ├── favicon.ico
| └── robots.txt
├── webpack.config.js # Webpack Config
├── postcss.config.js # Postcss config
└── package.json # Dependencies and site/folder configuration
Congratulations! You should now have successfully created a YOLO project and are ready to start building out your site/app.
Now you can run the following tasks:
npm run dev
for previewing your site/app on a development server.npm run build
for generating a production version of your site/app.
Note: Generators need to be run from the root directory of your app.
Creates a new page.
$ yo yolo:page contact
Produces:
src/contact/index.pug
Creates a new module.
$ yo yolo:module header
Produces:
src/_modules/header/header.pug
src/_modules/header/header.scss
src/_modules/header/header.js
Specify custom folder structure
$ yo yolo:module components/header
Produces:
src/_modules/components/header/header.pug
src/_modules/components/header/header.scss
src/_modules/components/header/header.js
This is a great way to create modules that adhere to atomic design
$ yo yolo:module link --atomic=atom
Produces:
src/_modules/atoms/link/link.pug
src/_modules/atoms/link/link.scss
src/_modules/atoms/link/link.js
NOTE: Possible
--atomic
options: atom, molecule, organism
If you want to load global data into your PUG templates, you can add JSON files in src/_data
folder.
For example, add menu.json in src/_data
folder:
{
"name": "Home",
"link": "/",
"category": "Page",
"status": "Development"
}
And it will be added to the site.data
object so it can be used like so:
div
h1= site.data.menu.name
Which outputs to:
<div>
<h1>Home</h1>
</div>
please visit the following link to learn more about image minification options.
If you are migrating a current yeogurt project to yolo, you need to do some changes in the files.
-
In Yeogurt global json data is available via the variable
site
, so that you can access the date likesite.data.somedata
. In YOLO global data is passed to pug via HTML WEBPACK PLUGIN, and the it is accessed viahtmlWebpackPlugin.options.data.somedata
. For new builds the generated pug template files already containes a variable- site = htmlWebpackPlugin.options
which will let you use global data as you always use it. When migrating you need to create this variable manually using search and replace. -
Plugins using browserify-shim In webpack jQuery is automatically loaded with the following references, So you don't need to import jquery in to your individual modules. Also different references of jQuery is automatically handled to avoid conflicts. See the reference code below. See Webpack Provide Plugin for more details.
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', $j: 'jquery' }),
What you need to do for easy import of these plugins is to register it under
resolve.alias
in the webpack.config.js. See below for example,resolve: { modules: [ "node_modules" ], alias: { niceSelect: path.resolve(__dirname, 'node_modules/jquery-nice-select/js/jquery.nice-select.js'), } },
Then you can import the module like
import niceSelect from 'niceSelect';
soMore information on this can be found at resolve webpack
-
One major difference between YOLO and YEOGURT is YOLO doesn't create a
tmp
folder when running development mode. Everything is serverd via available memmory.
- Feel free to learn more about Yeoman.
MIT © Akhil Prasenan