Example respository for creating a dev enviroment with Gulp, ESLint, Styelint, MarkoJS and Express. Supports autoprefixed, minified SASS compilation with source maps.
Note: This environment currently treats Marko as a server-side templating engine, not as an isomorphic (server + client) component library. An implementation for use with client-side components is in the works.
- Clone the repository
- Install dependencies via
yarn install - Run
yarn dev
This will run the default Gulp task (as defined in gulpfile.js) and set the NODE_ENV, LIVERELOAD_PORT and PORT environment variables.
Three commands are publically exposed:
serve(also thedefaultcommand): runs lint + build and starts the express/app server.lint: lints all JavaScript files (via ESLint) and SASS files (via Stylelint) within the./srcfolder.lint:js: only lint JavaScriptlint:scss: only lint SASS
build: builds all assets (currently SASS files) and stores them in the./distfolder.
Lints both JavaScript and SASS files.
- Runs ESlint on
src/**/*.jsbut will ignore compiled*.marko.jsfiles. Respects rules defined in.eslintrc.jsand.eslintignore. Uses theeslint-config-airbnb-baseconfiguration. - Runs Stylelint on
src/styles/**/*.scss. Respects rules defined in.stylelintrcand.stylelintignore. Uses thestylelint-config-twbs-bootstrapconfiguration.
Reads the src/styles/app.scss SASS file and transforms it into a regular CSS file with the following pipleline:
- Compile SASS using
node-sass - Autoprefix the CSS using
autoprefixerviapostcss(using browser targets corresponding to Bootstrap 4.3.1) - Minify the CSS using
cssnanoviapostcss - Write the sourcemap
- Save the
app.cssandapp.css.mapto the./distfolder
This command runs the dev environment:
- A browser live reload server is started and runs on
LIVERELOAD_PORT. This allows the browser to automatically refresh when files change. - All JavaScript (
.js), Marko template (.markonot.marko.js) and SASS (.scss) files are watched within the project./srcdirectory. - Anytime these files are changed, added, or removed the following tasks occur
- Lint all appropriate JavaScript and SASS files (via the
linttask) - Compile the
app.scssinto regular CSS (via thebuildtask) - Spawn a Node subprocess and run the Express server
- Once the Express server is ready, notify livereload to refresh the browser window
- Lint all appropriate JavaScript and SASS files (via the
For quicker linting inside VSCode, it's recommended to install the Stylelint and ESLint extensions.