solution • NodeJS — Initite a new project via npm packages ‐ SCSS or Tailwind stack - martindubenet/wed-dev-design GitHub Wiki
NOTE: The dollar signs $ mean a new command lines in your CLI Terminal.
$ cd ~/projects
$ mkdir project_folder
$ cd project_folder
This next command will launch the utility that will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
$ npm init
-
package name: Leave default value -
version: Leave default value -
description: Describe this project -
entry point: index.html -
test command: Leave empty -
git repository: Optional -
keywords: Leave empty -
author: My name -
licence: Leave empty
Use this approach when you need a custom SCSS architecture with variables, mixins, and partials.
- autoprefixer to add vendor prefixes where needed.
- browser-sync to live-reload the browser on file changes.
- clean-css-cli to create minified CSS versions.
-
sass (Dart Sass) to compile
.scssfiles to.css. - postcss-cli to run autoprefixer via CLI.
- stylelint to check the code for mistakes.
$ npm install <package_name> -D
Note: The trailing
-Dflag saves the package as adevDependencyinpackage.json
$ npm install autoprefixer -D
$ npm install clean-css-cli -D
$ npm install sass -D
$ npm install postcss-cli -D
$ npm install stylelint stylelint-scss stylelint-order stylelint-config-standard-scss -D
$ npm install browser-sync concurrently
npm install sass clean-css-cli autoprefixer postcss-cli stylelint stylelint-scss stylelint-order stylelint-config-standard-scss -D && npm install browser-sync concurrently
This package will refresh only the part of the page affected by the latest compiled SCSS (CSS injection method), making the page reload faster.
"scripts": {
"sass:watch": "sass --watch src/scss:dist/css --embed-sources",
"sass:build": "sass src/scss:dist/css --style=compressed",
"bs": "browser-sync start --proxy 'localhost:8080' --files 'dist/css/**/*.css, **/*.html'",
"dev": "concurrently \"npm run sass:watch\" \"npm run bs\""
}
All those Style Lint Rules define what is allowed and what will throw an error.
For example, "max-empty-lines": 2 will throw an error if you have more than 2 consecutive empty lines.
- Create the config file:
$ touch .stylelintrc.json - Paste the following minimal config:
{
"extends": ["stylelint-config-standard-scss"],
"rules": {
"max-empty-lines": 2,
"color-named": "never"
}
}PostCSS is required to run autoprefixer, which adds vendor prefixes automatically based on your browserslist.
Create the config file:
$ touch postcss.config.mjs
Paste this code:
export default {
plugins: {
autoprefixer: {},
},
}Add a browserslist array to your package.json to define which browsers to support:
"browserslist": [
"last 2 major versions",
">= 1%",
"Chrome >= 109",
"Firefox >= 115",
"Edge >= 109",
"Safari >= 16",
"iOS >= 16",
"Android >= 109",
"Opera >= 95",
"not dead"
],
$ mkdir -p src/scss/layout
$ cd src/scss
$ touch main.scss _variables.scss _mixins.scss _layout.scss
$ cd layout
$ touch _header.scss _footer.scss
// MAIN ENTRY POINT
// Load all partials in order
@use 'variables' as *;
@use 'mixins' as *;
@use 'layout';
@use 'layout/header';
@use 'layout/footer';Note:
@usereplaces the deprecated@importrule as of Dart Sass v1.23+. Variables and mixins imported with@useare namespaced by default (e.g.variables.$color).
Use this approach when you want utility-first CSS without writing custom SCSS.
⚠️ Tailwind CSS v4 is incompatible with Sass/SCSS preprocessors — choose one or the other.
$ npm install tailwindcss @tailwindcss/postcss postcss -D
Create the config file:
$ touch postcss.config.mjs
Paste this code:
export default {
plugins: {
"@tailwindcss/postcss": {},
},
}$ mkdir -p src/css
$ touch src/css/main.css
Add this single line at the top of src/css/main.css:
@import "tailwindcss";That's it — no
tailwind.config.jsneeded in v4. Tailwind detects your template files automatically.
All customizations are done directly in CSS using the @theme directive, right after the import:
@import "tailwindcss";
@theme {
--font-sans: "Inter", sans-serif;
--color-brand: oklch(0.55 0.22 260);
--breakpoint-xs: 480px;
}"scripts": {
"dev": "postcss src/css/main.css -o dist/css/main.css --watch",
"build": "NODE_ENV=production postcss src/css/main.css -o dist/css/main.css"
}<head>
<link rel="stylesheet" href="/dist/css/main.css">
</head>Then start using Tailwind utility classes directly in your markup:
<h1 class="text-3xl font-bold text-brand underline">Hello world!</h1>