GoPablo a static site generator.
- Introduction
- 1. Installing Node
- 2. Set Up Project
- 3. CSS, PostCSS and Sass
- 4. Images and Fonts
- 5. JavaScript ES6
- 6. External Libraries
- 7. Code Style Rules
- 8. Deploy
- 9. Audit and Page Speed
sudo npm i gopablo -g
Run GoPablo to generate the file structure:
gopablo
Build and open your browser to http://localhost:3000.
npm run dev
npm run prod
Ready to deploy π
GoPablo is a static site generator with a modern development workflow, integrated web server, auto-reload, CSS preprocessors, and ES6 ready.
π | Includes |
---|---|
π¦ | Live Server |
π₯ | Hot Reload & CSS Injection |
β | Babel 7 |
π€ | Express Server |
π | Code Minification |
π | Image Compression |
πΈ | Templating & Partial HTML Injection |
π¨ | PostCSS & Next Generation CSS |
βοΈ | Cache-Busting |
π | Distribution Files |
GoPablo requires Node v7.5+. This is the only global dependency. You can download Node here.
Node.js is a JavaScript runtime built on Chromeβs V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.jsβ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
βββ build/ # Build files
βββ dist/ # Distribution files
βββ src/ # Source files
β βββ assets/ # Assets directory
β βββ css/ # CSS files
β βββ fonts/ # Fonts directory
β βββ img/ # Image directory
β βββ js/ # JavaScript files
β βββ etc/ # Extra files
β βββ includes/ # HTML template partials
β βββ index.html # Index page
βββ .babelrc # Babel configuration
βββ .gitignore # Git ignored files
βββ .stylelintrc # Stylelint configuration file
βββ gulpfile.js # Gulp configuration
βββ LICENSE # License agreements
βββ package-lock.json # Packages lock file
βββ package.json # Node packages
βββ README.md # You are reading this
βββ server.js # Express server
To install GoPablo from NPM, run the command:
sudo npm i gopablo -g
START GOPABLO
- Create a directory for the new website and from there run GoPablo to generate the file structure:
gopablo
To install GoPablo you need to clone the repository from GitHub:
git clone https://github.com/luangjokaj/gopablo
-
This will clone the repository on your local machine. Navigate to the newly created folder.
-
Replace the file:
./package.json
with./installer/package.json
and continue with the dependency installation.
INSTALL DEPENDENCIES
npm install
START WORKFLOW
- We are ready to start our development server with the command:
npm run dev
To avoid repetitive HTML code, GoPablo uses gulp-file-include. It has a simple templating synthax and allows to re-use chunks of code written in separate files. These partials are located in the directory:
src/includes/
For more information check out their documentation and examples: https://github.com/haoxins/gulp-file-include
To create new pages, simply create new .html files in the src/
directory.
To generate your distribution files run the command:
npm run prod
The files will be generated in the dist/
directory.
By default GoPablo supports PostCSS, a similar preprocessor to Sass, Less and others but with more functionality. On top of that PostCSS is 3x faster than Sass and 4x faster than Less. Features come in the shape of PostCSS plugins. Think of these like using Lego, where each piece is a different feature that can transform your CSS in some way. PostCSS lets you stick these pieces together so that you can build up your own feature set, adding and removing plugins as and when you need them. postcss-preset-env is installed by default. Read more about PostCSS here.
POSTCSS PLUGINS
GoPablo has two different sets of PostCSS plugins - one for the development environment (pluginsListDev) and one for the production task (pluginsListProd).
//--------------------------------------------------------------------------------------------------
/* -------------------------------------------------------------------------------------------------
PostCSS Plugins
------------------------------------------------------------------------------------------------- */
const pluginsDev = [
postcssImport,
postCSSMixins,
postcssPresetEnv({
stage: 0,
features: {
'nesting-rules': true,
'color-mod-function': true,
'custom-media': true,
},
}),
];
const pluginsProd = [
postcssImport,
postCSSMixins,
postcssPresetEnv({
stage: 0,
features: {
'nesting-rules': true,
'color-mod-function': true,
'custom-media': true,
},
}),
require('cssnano')({
preset: [
'default',
{
discardComments: true,
},
],
}),
];
//--------------------------------------------------------------------------------------------------
WRITING CSS
The starting point for CSS is the file:
src/assets/css/styles.css
GoPablo is super flexible. You can install Sass and use it as the main CSS preprocessor:
npm install gulp-sass --save-dev
Include Sass in gulpfile.js:
const sass = require('gulp-sass');
Change the gulp tasks stylesDev to:
function stylesDev() {
return src('./src/assets/css/styles.scss')
.pipe(sourcemaps.init())
.pipe(sass({includePaths: 'node_modules'}).on("error", sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(dest('./build/assets/css'))
.pipe(browserSync.stream({ match: '**/*.css' }));
}
Also the watch task has to be changed in order to watch for .scss filetypes:
watch('./src/assets/css/**/*.scss', stylesDev);
Change the gulp tasks styleProd to:
function stylesProd() {
return src('./src/assets/css/styles.scss')
.pipe(sass({includePaths: 'node_modules'}).on("error", sass.logError))
.pipe(dest('./dist/assets/css'))
}
It is recommended to store image assets in the directory:
src/assets/img/
In the production build SVGs and other image assets will go through a minification process.
Fonts are always special. Your fonts should be stored in:
src/assets/fonts/
Then you can include them in your CSS:
@font-face {
font-family: 'Helvetica Neue Thin';
src: url('./fonts/Helvetica-Neue-Thin.eot');
src: url('./fonts/Helvetica-Neue-Thin.eot') format('eot'),
url('./fonts/Helvetica-Neue-Thin.woff2') format('woff2'),
url('./fonts/Helvetica-Neue-Thin.woff') format('woff'),
url('./fonts/Helvetica-Neue-Thin.ttf') format('truetype'),
url('./fonts/Helvetica-Neue-Thin.svg') format('svg');
}
GoPablo supports ES6 JavaScript with Babel. Babel has support for the latest version of JavaScript through syntax transformers. These plugins allow you to use new syntax, right now without waiting for browser support.
Your JavaScript code should be located in:
src/assets/js/
GoPablo will watch for changes under the js directory and bundle the code in a single file, which will be included in the footer of the page as:
footer-bundle.js
Check the gulp configuration to learn more about how JavaScript is generated.
Including external JavaScript libraries is as simple as installing the npm script and including it in the gulpfile.js
/* -------------------------------------------------------------------------------------------------
Header & Footer JavaScript Boundles
-------------------------------------------------------------------------------------------------- */
const headerJS = [
'./node_modules/jquery/dist/jquery.js',
'./node_modules/nprogress/nprogress.js',
'./node_modules/aos/dist/aos.js',
'./node_modules/isotope-layout/dist/isotope.pkgd.js'
];
const footerJS = [
'./src/assets/js/**'
];
//--------------------------------------------------------------------------------------------------
You can include the scripts in the head of the page before the DOM is loaded by placing them in the headerJS array or in the footer of the page after the DOM is loaded in the footerJS array. Only footer scripts are processed with Babel thus supporting ES6, however you can change this in the configuration if you want to run both header and footer scripts with Babel.
A build restart is required for changes to take effect.
GoPablo comes with its own set of code style rules:
.stylelintrc
Before pushing changes make sure you have clean and consistent CSS. Run stylelint with the command:
npm run lint
There are a lot of possiblities and different ways to deploy your static website. The most traditional one being: generating your distribution files and uploading them manually, usually FTP.
With the help of a simple Express server, with GoPablo we can deploy to heroku out of the box.
- Create Heroku application:
heroku create
. - Push the branch to Heroku origins:
git push heroku master
Netlify is a great service that can be used to deploy generated websites. All you have to do is:
- Connect your GitHub repository.
- Choose Branch to deploy, usually:
master
. - Set the Build command to:
npm run prod
. - Set the Publish directory to:
dist/
.
We are live π
v0.1.3
- π FIX: Do not rename html files
dontUpdateReference
while caching busting. - π DOC: Improve documentation.
v0.1.2
- π RELEASE: Install files from versioned release instead of
master
branch.
v0.1.1
- π IMPROVE: Install only required dependencies.
- π RELEASE: Update dependencies.
v0.1.0
- π RELEASE: Update dependencies.
- π DOC: Improve documentation.
v0.0.9
- π RELEASE: Improved installation speed for global dependencies.
- BREAKING CHANGE: It is required to update GoPablo:
sudo npm install gopablo -g
.
v0.0.8
- π IMPROVE: Meta.
v0.0.7
- π RELEASE: Update dependencies.
v0.0.6
- π¦ NEW: Confirm installation directory.
v0.0.5
- π RELEASE: Check version with command:
gopablo -v
.
v0.0.4
- π FIX: Correct typo.
- π DOC: Improve documentation.
v0.0.3
- π FIX: Missing modules.
- π DOC: Improve documentation.
v0.0.2
- π¦ NEW: Run GoPablo globally from NPM.
- π¦ NEW: Add
manifest.json
.
v0.0.1
- π¦ NEW: Meet GoPablo.
MIT