Skip to content

Commit ff94ea4

Browse files
docs: update README with features, instructions, tips and other notes
1 parent 25b359f commit ff94ea4

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,128 @@ A WordPress boilerplate to develop themes with webpack.
1212

1313
* In order to avoid the warnings related to the local use of `https`, you will need a valid certificate. You can achieve this with [mkcert](https://github.com/FiloSottile/mkcert).
1414

15+
## Features
16+
17+
### What is included?
18+
19+
* [BabelJS](https://babeljs.io/)
20+
* [Commitlint](https://commitlint.js.org/)
21+
* [Dotenv](https://github.com/motdotla/dotenv) and [PHPDotenv](https://github.com/vlucas/phpdotenv)
22+
* [ESlint](https://github.com/eslint/eslint)
23+
* [Husky](https://github.com/typicode/husky)
24+
* [Lint-staged](https://github.com/okonet/lint-staged)
25+
* [Modern-normalize](https://github.com/sindresorhus/modern-normalize)
26+
* [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
27+
* [Playwright](https://github.com/microsoft/playwright)
28+
* [PostCSS](https://postcss.org/)
29+
* [RTLCSS](https://rtlcss.com/)
30+
* [Standard version](https://github.com/conventional-changelog/standard-version)
31+
* [Stylelint](https://github.com/stylelint/stylelint)
32+
* [webpack](https://webpack.js.org/)
33+
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
34+
* [WordPress-Prettier](https://github.com/Automattic/wp-prettier)
35+
* [wp-pot](https://github.com/wp-pot/wp-pot)
36+
37+
### webpack
38+
39+
webpack will:
40+
41+
* compile Sass to CSS and process styles with postcss and autoprefixer,
42+
* generate `style.css` in the theme root,
43+
* generate `editor.css` and `print.css` in `assets/css`,
44+
* transpile JS files with Babel and output them in `assets/js`,
45+
* compress images in `src/images` and copy them in `assets/images`,
46+
* handle fonts by copying `src/fonts` to `assets/fonts`.
47+
48+
webpack comes with two mode: `development` and `production`. Here the difference for JS and CSS files :
49+
50+
|Features|`development`|`production`|
51+
|---|:-:|:-:|
52+
|Hot Module Replacement||𐄂|
53+
|Live Reload||𐄂|
54+
|Minify|𐄂||
55+
|Sourcemaps||𐄂|
56+
|Written to disk|𐄂||
57+
58+
### npm scripts
59+
60+
With `npm`, you can use some scripts:
61+
62+
* `npm run build`: write assets in `assets` folder and generate RTL version for each CSS file.
63+
* `npm run watch`: build assets in dev mode and continue to watch for changes.
64+
* `npm run serve`: launch webpack dev server, open your website in the desired browser and refresh it on changes.
65+
* `npm run lint`: check if all files respects your coding standards.
66+
* `npm run fix`: fix all files to comply with your coding standards.
67+
* `npm run rtl`: generate a RTL version of each CSS file.
68+
* `npm run translate`: generate a `.pot` file in `./languages`.
69+
* `npm run screenshot`: take a screenshot (`1200x900`) of your homepage and save `screenshot.png` in your theme root.
70+
* `npm run release`:
71+
* bump `package.json`, `readme.txt`, `functions.php` and `src/scss/abstracts/_variables.scss`,
72+
* launch build to update version in `style.css`,
73+
* create a new commit with a new tag for your release.
74+
* `npm run zip`: create a compressed file of your theme, excluding files needed only in development mode.
75+
76+
To lint/fix a specific type of files, you can also use a "sub" script:
77+
* `npm lint:js` / `npm fix:js` for JS files,
78+
* `npm lint:php` / `npm fix:php` for PHP files,
79+
* `npm lint:scss` / `npm fix:scss` for SCSS files.
80+
81+
## How to use it
82+
83+
### First steps
84+
85+
Clone this repo, copy `wordpress-theme` in your WordPress installation ( `wp-content/themes/` ) and rename it. Then, in your theme directory:
86+
87+
1. Init Git (otherwise Husky will not install hooks)
88+
2. Launch `npm install` and `composer update`
89+
3. Execute `npx husky install` to install Git hooks
90+
4. Copy `.env.example` and rename it `.env`
91+
5. Edit your `.env` file to suit your project.
92+
6. Launch `npm run init`
93+
7. You may want to relaunch `npm install` so that your `package-lock.json` contains the correct information.
94+
95+
That's it! You can now start developing your theme.
96+
97+
### Complete the configuration
98+
99+
If you need to complete the boilerplate:
100+
101+
* `tools/` contains files required by webpack and npm scripts,
102+
* `tools/bump/` contains files used to bump version,
103+
* `tools/utils/` contains files that can be reused between scripts,
104+
* `tools/webpack/` contains webpack config in addition to `webpack.config.js` in the theme root,
105+
* `tools/init.js` is used to init your theme,
106+
* `tools/screenshot.js` is used to take a screenshot of your website,
107+
* `tools/translate.js` handle the `.pot` generation for translation,
108+
* `tools/zip.js` handle the `.zip` generation.
109+
110+
## Tips
111+
112+
### Formatting JS files in VS Code with Prettier and ESlint
113+
114+
If you are using Prettier extension to auto-fix your files, you may want to disable it for Javascript. Prettier doesn't work well with ESlint rules (in particular space rules). So, I recommend you to set these settings in your workspace:
115+
116+
```json
117+
{
118+
"editor.codeActionsOnSave": {
119+
"source.fixAll": true,
120+
},
121+
"editor.formatOnSave": true,
122+
"[javascript]": {
123+
"editor.formatOnSave": false,
124+
}
125+
}
126+
```
127+
This way, only the ESlint extension will be used to format your JS files.
128+
129+
## Additional Notes
130+
131+
If you plan to publish your theme on [WordPress Theme directory](https://wordpress.org/themes/), you may want to edit `readme.txt` manually to provides all necessary information. I'm not sure this is required for themes (it is for plugins), but it is at least recommended. See [a revised readme](https://make.wordpress.org/themes/2015/04/29/a-revised-readme/) for an example.
132+
133+
You need at least `410MiO` of free space*: `node_modules` is about `200 Mio` but a dependency (`playwright-firefox`) also creates a folder of about `206 Mio` in your cache directory. I have chosen the Firefox version because the webkit version did not work on my system and the Chromium version took a little more space.
134+
135+
*The sizes are given for information only, they may vary.
136+
15137
## License
16138

17139
This project is open-sourced and available under the [GPL-v2-or-later](./LICENSE) license.

0 commit comments

Comments
 (0)