-
I want to set up a modern environment for theme development. I would like to use wp-scripts to automatically process the JS, CSS, SCSS as it is done for blocks. I really miss guides on how to work with themes. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 9 replies
-
Hi @cawa-93, There are various ways to build JS and SCSS for a theme, but below is an example of a script that I often use.
{
"name": "my-theme",
"scripts": {
"start:sass": "sass src/sass/one.scss:build/css/one.css src/sass/two.scss:build/css/two.css --watch",
"start:js": "wp-scripts start src/js/one.js src/js/two.js --output-path=build/js",
"build:sass": "sass src/sass/one.scss:build/css/one.css src/sass/two.scss:build/css/two.css --no-source-map --style compressed",
"build:js": "wp-scripts build src/js/one.js src/js/two.js --output-path=build/js",
"clean": "rimraf build"
},
"devDependencies": {
"@wordpress/scripts": "^26.13.0"
}
} |
Beta Was this translation helpful? Give feedback.
-
You might find this article by Justin Tadlock helpful: There are plenty more really good articles on that blog, under the "Theme" tag, but also for other development topics. |
Beta Was this translation helpful? Give feedback.
-
I agree with @vicobot-0815 that Justin's tutorial post is very helpful. And good news! There is also now (as of January 2024) official documentation for using the |
Beta Was this translation helpful? Give feedback.
-
I have also just switched to working with wp-scripts. I found it helpful that pnpm workspaces come in handy when working with wp-scripts on plugins and themes at the same time. |
Beta Was this translation helpful? Give feedback.
-
Does anyone have any pointer on how to use |
Beta Was this translation helpful? Give feedback.
-
You could import assets in javascript, but that is a limited option (if they are importable - not all assets could be imported with import). |
Beta Was this translation helpful? Give feedback.
I agree with @vicobot-0815 that Justin's tutorial post is very helpful. And good news! There is also now (as of January 2024) official documentation for using the
wp-scripts
package for a theme build process. That can be found here: https://developer.wordpress.org/themes/advanced-topics/build-process/