mirror of
https://github.com/locomotivemtl/locomotive-boilerplate.git
synced 2026-01-15 00:55:08 +08:00
Update tasks - remove gulp (replaced by node scripts, working with mconfig) + esbuild (no more es5 support) + add critical css in config file
This commit is contained in:
18
README.md
18
README.md
@@ -8,39 +8,29 @@
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
```sh
|
```sh
|
||||||
npm install mbp -g
|
npm i
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```sh
|
```sh
|
||||||
# init your project
|
# start it
|
||||||
mbp init locomotivemtl/locomotive-boilerplate <directory>
|
|
||||||
|
|
||||||
# and start it
|
|
||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
Change the mentions of `boilerplate` for your project's name in `mconfig.json`. It is based on [modularBP](https://github.com/modularorg/modularbp).
|
Change the mentions of `locomotive-boilerplate` for your project's name in `mconfig.json`. Legacy from [modularBP](https://github.com/modularorg/modularbp).
|
||||||
|
|
||||||
[Learn more](https://github.com/modularorg/modularbp)
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
[gulp](https://github.com/gulpjs/gulp) is our build system. It compiles our styles and scripts, generate svg sprites, live reload the browser and minify everything.
|
|
||||||
|
|
||||||
#### Tasks
|
#### Tasks
|
||||||
```sh
|
```sh
|
||||||
# watch
|
# watch
|
||||||
npm start
|
npm start
|
||||||
|
|
||||||
# compile
|
# build
|
||||||
npm run compile
|
|
||||||
|
|
||||||
# minify
|
|
||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
[Learn more](https://github.com/modularorg/modularbp-gulp)
|
|
||||||
|
|
||||||
## Styles
|
## Styles
|
||||||
[Sass](https://github.com/sass/node-sass) is our CSS preprocessor. [Autoprefixer](https://github.com/postcss/autoprefixer) is also included.
|
[Sass](https://github.com/sass/node-sass) is our CSS preprocessor. [Autoprefixer](https://github.com/postcss/autoprefixer) is also included.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ window.onload = (event) => {
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
globals();
|
globals();
|
||||||
|
|
||||||
app.init(app);
|
app.init(app);
|
||||||
|
|
||||||
html.classList.add('is-loaded');
|
html.classList.add('is-loaded');
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export default class extends module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
||||||
const load = new modularLoad({
|
const load = new modularLoad({
|
||||||
enterDelay: 0,
|
enterDelay: 0,
|
||||||
transitions: {
|
transitions: {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export default class extends module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
||||||
this.scroll = new LocomotiveScroll({
|
this.scroll = new LocomotiveScroll({
|
||||||
el: this.el,
|
el: this.el,
|
||||||
smooth: true
|
smooth: true
|
||||||
|
|||||||
0
assets/styles/critical.scss
Normal file
0
assets/styles/critical.scss
Normal file
9
build/build.js
Normal file
9
build/build.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { buildScripts } from './scripts.js';
|
||||||
|
import { concatVendors } from './concat.js';
|
||||||
|
import { compileStyles } from './styles.js' ;
|
||||||
|
import { generateSpriteSVG } from './svgs.js' ;
|
||||||
|
|
||||||
|
buildScripts();
|
||||||
|
concatVendors();
|
||||||
|
compileStyles();
|
||||||
|
generateSpriteSVG();
|
||||||
@@ -1,14 +1,30 @@
|
|||||||
import gulp from 'gulp';
|
|
||||||
import gulpConcat from 'gulp-concat';
|
|
||||||
import paths from '../mconfig.json';
|
import paths from '../mconfig.json';
|
||||||
|
import message from './utils/message.js';
|
||||||
|
import fs from 'fs';
|
||||||
|
import concat from 'concat';
|
||||||
|
|
||||||
function concat() {
|
export function concatVendors() {
|
||||||
return gulp
|
// Get all files in scripts/vendors/
|
||||||
.src([
|
const files = fs.readdirSync(paths.scripts.vendors.src);
|
||||||
`${paths.scripts.vendors.src}*.js`
|
|
||||||
])
|
// Extract no-JS files
|
||||||
.pipe(gulpConcat(`${paths.scripts.vendors.main}.js`))
|
var jsFiles = files.filter((f)=>{
|
||||||
.pipe(gulp.dest(paths.scripts.dest));
|
if(f.includes('.js')) {
|
||||||
}
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add absolute path
|
||||||
|
jsFiles = jsFiles.map((f) => {
|
||||||
|
return `${paths.scripts.vendors.src + f}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// add files in node_modules example:
|
||||||
|
// jsFiles.push('node_modules/gsap/dist/gsap.min.js');
|
||||||
|
message('Concatenating vendors...', 'waiting');
|
||||||
|
|
||||||
export default concat;
|
concat(jsFiles, paths.scripts.dest + paths.scripts.vendors.main + '.js')
|
||||||
|
}
|
||||||
16
build/scripts.js
Normal file
16
build/scripts.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import esbuild from 'esbuild';
|
||||||
|
import paths from '../mconfig.json';
|
||||||
|
import message from './utils/message.js';
|
||||||
|
|
||||||
|
export function buildScripts() {
|
||||||
|
message('Compiling JS...', 'waiting');
|
||||||
|
|
||||||
|
esbuild.buildSync({
|
||||||
|
entryPoints: [paths.scripts.src + paths.scripts.main + '.js'],
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
sourcemap: true,
|
||||||
|
target: ['es2015'],
|
||||||
|
outfile: paths.scripts.dest + paths.scripts.main + '.js'
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import browserSync from 'browser-sync';
|
|
||||||
import paths from '../mconfig.json';
|
|
||||||
|
|
||||||
export const server = browserSync.create();
|
|
||||||
|
|
||||||
function serve(done) {
|
|
||||||
server.init({
|
|
||||||
notify: false,
|
|
||||||
proxy: paths.url,
|
|
||||||
host: paths.url,
|
|
||||||
open: false,
|
|
||||||
ghostMode: false
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
|
|
||||||
export default serve;
|
|
||||||
49
build/styles.js
Normal file
49
build/styles.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
import sass from 'node-sass';
|
||||||
|
import paths from '../mconfig.json';
|
||||||
|
import fs from 'fs';
|
||||||
|
import message from './utils/message.js';
|
||||||
|
|
||||||
|
export function compileStyles() {
|
||||||
|
|
||||||
|
// Compile main scss
|
||||||
|
sass.render({
|
||||||
|
file: paths.styles.src + paths.styles.main + '.scss',
|
||||||
|
outFile: paths.styles.dest + paths.styles.main + '.css',
|
||||||
|
outputStyle: 'compressed',
|
||||||
|
sourceMap: true
|
||||||
|
}, (error, result) => {
|
||||||
|
|
||||||
|
if(error) {
|
||||||
|
message('Error compile main.scss', 'error');
|
||||||
|
console.log(error);
|
||||||
|
} else {
|
||||||
|
message('main.scss compiled', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!error){
|
||||||
|
// No errors during the compilation, write this result on the disk
|
||||||
|
fs.writeFile(paths.styles.dest + paths.styles.main + '.css', result.css, (err) => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Compile critical scss
|
||||||
|
sass.render({
|
||||||
|
file: paths.styles.src + paths.styles.critical + '.scss',
|
||||||
|
outFile: paths.styles.dest + paths.styles.critical + '.css',
|
||||||
|
outputStyle: 'compressed',
|
||||||
|
sourceMap: true
|
||||||
|
}, (error, result) => {
|
||||||
|
|
||||||
|
if(error) {
|
||||||
|
message('Error compile critical.scss', 'error');
|
||||||
|
console.log(error);
|
||||||
|
} else {
|
||||||
|
message('critical.scss compiled', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!error){
|
||||||
|
// No errors during the compilation, write this result on the disk
|
||||||
|
fs.writeFile(paths.styles.dest + paths.styles.critical + '.css', result.css, (err) => {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
12
build/svgs.js
Normal file
12
build/svgs.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import mixer from 'svg-mixer';
|
||||||
|
import paths from '../mconfig.json';
|
||||||
|
import message from './utils/message.js';
|
||||||
|
|
||||||
|
export function generateSpriteSVG() {
|
||||||
|
// Write sprite content on disk
|
||||||
|
mixer([paths.svgs.src + '*.svg'], {spriteConfig: { usages: false }})
|
||||||
|
.then((result) => {
|
||||||
|
message('SVG Sprite generated', 'success');
|
||||||
|
result.write(paths.svgs.dest + 'sprite.svg')
|
||||||
|
});
|
||||||
|
}
|
||||||
14
build/utils/message.js
Normal file
14
build/utils/message.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
// colors reference : https://coderwall.com/p/yphywg/printing-colorful-text-in-terminal-when-run-node-js-script
|
||||||
|
export default function message(text, type) {
|
||||||
|
|
||||||
|
if(type === 'success') {
|
||||||
|
console.log(`\x1b[42m \x1b[30m`, `✅ ${text}`, `\x1b[0m`);
|
||||||
|
} else if (type === 'error') {
|
||||||
|
console.log(`\x1b[41m \x1b[37m`,`🚨 ${text}`, `\x1b[0m`);
|
||||||
|
} else if (type === 'waiting') {
|
||||||
|
console.log(`\x1b[43m \x1b[30m`,`⏱ ${text}`, `\x1b[0m`);
|
||||||
|
} else {
|
||||||
|
console.log(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,69 @@
|
|||||||
import gulp from 'gulp';
|
import { buildScripts } from './scripts.js';
|
||||||
|
import { concatVendors } from './concat.js';
|
||||||
|
import { compileStyles } from './styles.js' ;
|
||||||
|
import { generateSpriteSVG } from './svgs.js';
|
||||||
|
|
||||||
import paths from '../mconfig.json';
|
import paths from '../mconfig.json';
|
||||||
import styles from './styles.js';
|
|
||||||
import scripts from './scripts.js';
|
|
||||||
import svgs from './svgs.js';
|
|
||||||
import concat from './concat.js';
|
|
||||||
import { server } from './serve.js';
|
|
||||||
|
|
||||||
function watch() {
|
// Create an named instance in one file...
|
||||||
gulp.watch(paths.styles.src, styles);
|
import bs from 'browser-sync';
|
||||||
gulp.watch(paths.scripts.src, gulp.series(scripts, reload));
|
|
||||||
gulp.watch(paths.scripts.vendors.src, concat);
|
|
||||||
gulp.watch(paths.views.src, reload);
|
|
||||||
gulp.watch(paths.svgs.src, gulp.series(svgs, reload));
|
|
||||||
}
|
|
||||||
|
|
||||||
function reload(done) {
|
// Start the Browsersync server
|
||||||
server.reload();
|
bs.init({
|
||||||
done();
|
proxy: paths.url,
|
||||||
}
|
open: false,
|
||||||
|
notify: false
|
||||||
|
});
|
||||||
|
|
||||||
export default watch;
|
// and call any methods on it.
|
||||||
|
bs.watch(
|
||||||
|
[
|
||||||
|
paths.views.src,
|
||||||
|
paths.scripts.dest + paths.scripts.main + '.js',
|
||||||
|
paths.scripts.dest + paths.scripts.vendors.main + '.js',
|
||||||
|
paths.styles.dest + paths.styles.main + '.css',
|
||||||
|
paths.svgs.dest + 'sprite.svg'
|
||||||
|
]
|
||||||
|
).on('change', bs.reload);
|
||||||
|
|
||||||
|
// Build scripts and compile styles on first hit
|
||||||
|
buildScripts();
|
||||||
|
concatVendors();
|
||||||
|
compileStyles();
|
||||||
|
generateSpriteSVG();
|
||||||
|
|
||||||
|
// Watch scripts
|
||||||
|
bs.watch(
|
||||||
|
[
|
||||||
|
paths.scripts.src + '**/*.js'
|
||||||
|
]
|
||||||
|
).on('change', () => {
|
||||||
|
buildScripts();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Watch scripts vendors
|
||||||
|
bs.watch(
|
||||||
|
[
|
||||||
|
paths.scripts.vendors.src + '*.js'
|
||||||
|
]
|
||||||
|
).on('change', () => {
|
||||||
|
concatVendors();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Watch styles
|
||||||
|
bs.watch(
|
||||||
|
[
|
||||||
|
paths.styles.src + '**/*.scss'
|
||||||
|
]
|
||||||
|
).on('change', () => {
|
||||||
|
compileStyles();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Watch svgs
|
||||||
|
bs.watch(
|
||||||
|
[
|
||||||
|
paths.svgs.src + '*.svg'
|
||||||
|
]
|
||||||
|
).on('change', () => {
|
||||||
|
generateSpriteSVG();
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import gulp from 'gulp';
|
|
||||||
import styles from './build/styles.js';
|
|
||||||
import scripts from './build/scripts.js';
|
|
||||||
import concat from './build/concat.js';
|
|
||||||
import svgs from './build/svgs.js';
|
|
||||||
import serve from './build/serve.js';
|
|
||||||
import watch from './build/watch.js';
|
|
||||||
import { buildStyles, buildScripts } from './build/build.js';
|
|
||||||
|
|
||||||
const compile = gulp.series(styles, scripts, svgs, concat);
|
|
||||||
const main = gulp.series(compile, serve, watch);
|
|
||||||
const build = gulp.series(compile, buildStyles, buildScripts);
|
|
||||||
|
|
||||||
gulp.task('default', main);
|
|
||||||
gulp.task('compile', compile);
|
|
||||||
gulp.task('build', build);
|
|
||||||
11
mconfig.json
11
mconfig.json
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"url": "boilerplate.test",
|
"url": "locomotive-boilerplate.test",
|
||||||
"src": "./assets/",
|
"src": "./assets/",
|
||||||
"dest": "./www/",
|
"dest": "./www/",
|
||||||
"build": "./build/",
|
"build": "./build/",
|
||||||
"styles": {
|
"styles": {
|
||||||
"src": "./assets/styles/",
|
"src": "./assets/styles/",
|
||||||
"dest": "./www/assets/styles/",
|
"dest": "./www/assets/styles/",
|
||||||
"main": "main"
|
"main": "main",
|
||||||
|
"critical": "critical"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"src": "./assets/scripts/",
|
"src": "./assets/scripts/",
|
||||||
@@ -23,11 +24,5 @@
|
|||||||
},
|
},
|
||||||
"views": {
|
"views": {
|
||||||
"src": "./views/boilerplate/template/"
|
"src": "./views/boilerplate/template/"
|
||||||
},
|
|
||||||
"modules": {
|
|
||||||
"build": "gulp",
|
|
||||||
"style": "sass",
|
|
||||||
"script": "js",
|
|
||||||
"view": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6837
package-lock.json
generated
Normal file
6837
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -3,20 +3,25 @@
|
|||||||
"name": "@locomotivemtl/boilerplate",
|
"name": "@locomotivemtl/boilerplate",
|
||||||
"title": "Locomotive Boilerplate",
|
"title": "Locomotive Boilerplate",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
"author": "Locomotive <info@locomotive.ca>",
|
"author": "Locomotive <info@locomotive.ca>",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "gulp",
|
"start": "node --experimental-json-modules build/watch.js",
|
||||||
"build": "gulp build",
|
"build": "node --experimental-json-modules build/build.js"
|
||||||
"compile": "gulp compile"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"locomotive-scroll": "*",
|
"locomotive-scroll": "*",
|
||||||
"modujs": "*",
|
"modujs": "^1.4.2",
|
||||||
"modularload": "*",
|
"modularload": "^1.2.6",
|
||||||
"normalize.css": "*",
|
"normalize.css": "*",
|
||||||
"svg4everybody": "*"
|
"svg4everybody": "*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gulp-concat": "*"
|
"browser-sync": "^2.26.13",
|
||||||
|
"concat": "^1.0.3",
|
||||||
|
"esbuild": "^0.8.16",
|
||||||
|
"fs": "0.0.1-security",
|
||||||
|
"node-sass": "^5.0.0",
|
||||||
|
"svg-mixer": "^2.3.14"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
www/assets/images/sprite.svg
Normal file
1
www/assets/images/sprite.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg width="0" height="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs></defs></svg>
|
||||||
|
After Width: | Height: | Size: 123 B |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
www/assets/styles/critical.css
Normal file
2
www/assets/styles/critical.css
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
/*# sourceMappingURL=critical.css.map */
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user