Importing pattern library static assets into your project
The node_modules
directory is typically excluded from version control, so it’s not possible to deploy its contents to a web server. For this reason, we must copy static asset files (i.e. images, SVGs, fonts, etc.) from the node_modules/tgam-patterns/patterns/
directory into a directory in your project that can be deployed to a web server.
Note: If your project uses version control, then you’ll probably want to commit the copied files.
Create a build task
You’ll need to create a build task in order to copy static files out of the node_modules
directory:
- Create a Node, Gulp or Grunt task that copies the static asset files. You’ll probably want this task to run as a
postinstall
hook, in yourpackage.json
, to ensure that the static assets get copied immediately after a new version oftgam-patterns
is installed. For example:
"scripts": {
"postinstall": "node copy-static-assets.js"
}
Or, if you’re using Gulp:
"scripts": {
"postinstall": "gulp copy-static-assets"
}
You’d then need to create a JavaScript file called copy-static-assets.js
or a Gulp task called copy-static-assets
to do the work of copying the files.
TODO: Write some example code to demonstrate how this can be done.