-
Notifications
You must be signed in to change notification settings - Fork 406
Running Pattern Lab Node as an npm Dependency
Note Following functionality was added in the v1.1.0 Release of Pattern Lab Node) and is no longer supported verbatim as described below.
Often, Pattern Lab is used in conjunction with other design and development tools to create modular, pattern-driven designs. To these ends, Pattern Lab needs to be a reliable, durable dependency if it's to be incorporated into team workflows.
Note The following steps describe in general how a user could integrate Pattern Lab Node as an npm dependency to a parent system which houses the source and generated patterns. The steps are generalized and cannot possibly cover every consumption scenario. Incorporating Pattern Lab Node as a dependency into a larger parent system will likely invalidate a lot of the following documentation, because you will likely already have similar or competing tasks for copying file, hosting files, etc and will therefore not be able to use the shipped Grunt/Gulpfile. If this is the case, use their contents to guide what files need to move where. Support for this configuration is still young, and is still being actively worked on. Expect a few bumps in the road and feel free to report any issues you have along with a thorough writeup.
Prerequisites: Node/npm, and a project with gulp and/or grunt installed. Commands are given in bash.
-
Install Pattern Lab: Go to your project root and run
npm install --save-dev patternlab-node
-
Copy the default config: you can call it whatever you want, but in this example, we do
cp node_modules/patternlab-node/patternlab-config.json patternlab-config.json
-
Copy the default source: you need a basic copy of the patternlab source files to get started. Do
cp -r node_modules/patternlab-node/source .
-
Create the public and public/patterns folders: on a Unix machine, that's
mkdir public; mkdir public/patterns
-
Copy the Gulpfile or Gruntfile: Either
cp node_modules/patternlab-node/gulpfile.js .
orcp node_modules/patternlab-node/Gruntfile.js .
- Edit your patternlab-config.json file:
- In the
paths
object at the top, tell Pattern Lab where to build its static HTML site; the default is[project root]/public
. Notice if you change the root you will likely have to change other entries to mirror the structure. You'll likely want to point it up to thesource
directory andpublic
directory you just copied. Absolute or relative paths should suffice. If you intend to house your source and public folders as a parent of the node_modules/patternlab-node module, you will have to specify this now. -
Edit the
paths()
function to point topatternlab-config.json
or whatever you chose to call your custom config file.
-
Install npm dependencies needed for the gulpfile:
npm install --save-dev del gulp-strip-banner gulp-header gulp-nodeunit gulp-load browser-sync
-
Edit your gulpfile Comment out this line, currently at or near line 28:
gulp.loadTasks(__dirname+'/builder/patternlab_gulp.js');
We need our own version of thepatternlab
task, not the default that's included. -
Create a custom
patternlab
task inside your gulpfile that loads your project's pattern lab config and passes it in. Something like:// The config and the Pattern Lab itself var config = require('./patternlab-config.json'), pl = require('patternlab-node')(config); gulp.task('patternlab', ['prelab'], function (done) { pl.build(true); done(); });
-
Run it and see if it works!
gulp serve
-
Install npm dependencies needed for the gruntfile:
npm install --save-dev bs-html-injector grunt-browser-sync grunt-contrib-concat grunt-contrib-copy grunt-contrib-nodeunit grunt-contrib-watch
-
Edit your Gruntfile Comment out this line, currently at or near line 128:
grunt.task.loadTasks('./builder/');
We need our own version of thepatternlab
task, not the default that's included. -
Create a custom
patternlab
task in your gruntfil that loads your project's pattern lab config and passes it in. Something like:// The config and the Pattern Lab itself var config = require('./patternlab-config.json'), pl = require('patternlab-node')(config); grunt.registerTask('patternlab', function (done) { pl.build(true); });
-
Run it and see if it works!
grunt serve
Reference examples of a parent projects running Pattern Lab Node as a dependency can be found here