2.0 KiB
2.0 KiB
Documentation on development
Using yarn
yarn
is a package manager running on nodejs
. It is veru useful to manage javascript
or css
projects.
Adding a new package
- find the name of the wanted package on the website https://www.npmjs.com
- on command line interface, on the root folder of this project, type
yarn add --dev name-of-the-package
- Identify the needed files into folder
node_modules/name-of-the-package
; most of time, files are into foldernode_modules/name-of-the-package/dist
- modifify the file
js/extract-files-from-node-modules
to a new line for each file to import in the theme :
copySync('node_modules/name-of-the-package/dist/js/file.min.js','js/vendor/name-of-the-package/file.min.js',{ overwrite: true })
forjavascript
filecopySync('node_modules/name-of-the-package/dist/css/file.min.css','css/vendor/name-of-the-package/file.min.css',{ overwrite: true })
forcss
file- do not forget
LICENCE
file of the package,copySync('node_modules/name-of-the-package/dist/LICENCE','css/vendor/name-of-the-package/LICENCE',{ overwrite: true })
forcss
(and forjavascript
)
- type
yarn install
in commpand line interface to start this script - add a new line in concerned
twig
file (example :includes/_head.twig
) to use the new file (example :<link href="{{ theme_url }}/css/vendor/name-of-the-package/file.min.css" rel="stylesheet" type="text/css" />
)
Removing a new package
- find the name of the wanted package into file
package.json
- on command line interface, on the root folder of this project, type
yarn remove name-of-the-package
- Identify the associated files into folders
js/vendor
andcss/vendor
and delete them - modifify the file
js/extract-files-from-node-modules
to remove lines related to this package - remove line in concerned
twig
file (example :includes/_head.twig
) that uses the new file (example :<link href="{{ theme_url }}/css/vendor/name-of-the-package/file.min.css" rel="stylesheet" type="text/css" />
)