I’m relatively new to WordPress development, and I’m trying to make us of a package called @wordpress/scripts which will allow me to automate the build of JS and SCSS/CSS.
The information about this package is here.
I have node.js installed, and I’ve used it to generate a package.json file:
{"name": "db-theme",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"Dependencies": {
"@wordpress/scripts": "^23.1.0"
}
}
…which I have then placed in my theme’s root folder.
When I run npm install
I end up with a node_modules folder, but if I try to run np run start
to create a build and src folder, with index.js, my terminal tells me npm ERR! Missing script: "start"
, which indicates the package has not been set up as expected.
I realise this is a potentially broad request, but can anyone tell me where I’m going wrong please?
2
Answers
Read documentation of this package.
In Setup section You have complete setup of scripts.
You need to specify "scripts" in Your packege.json in order to use commands.
Afer adding this You will be able to use commands like ‘npm run build’
I personally can recommend "Roots Bud" – it has everything you need included, and needs only little tweaking. It is made for WordPress specifically.
https://roots.io/bud/
Alternatively you could also use "Roots Sage 10" theme starter, which already has the build process included. However it is quite advanced in general, so a good knowledge of how WordPress works is recommended.