Skip to content

Commit c3354e7

Browse files
committed
refactor: update the UIKIt build to recompile PL when the config changes
1 parent a259165 commit c3354e7

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/uikit-workshop/build-tools.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ patternlab.build({
1212

1313
webpackServer.serve(
1414
patternlab,
15+
configFilePath,
1516
path.resolve(process.cwd(), config.paths.public.root)
1617
);

packages/uikit-workshop/build/webpack-server.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const portfinder = require('portfinder');
1212

1313
const fileHashes = {};
1414

15-
async function serve(patternlab, buildDir = 'public') {
15+
async function serve(patternlab, configPath, buildDir = 'public') {
1616
// @todo: move these configs + make customizable?
1717
const root = path.resolve(__dirname, `${buildDir}`);
1818
const preferredPort = 3000;
1919
portfinder.basePort = preferredPort;
2020

2121
const webpackConfigs = await webpackConfig({
22-
watch: false,
22+
watch: true,
2323
prod: false,
2424
buildDir: root,
2525
rootDir: process.cwd(),
@@ -37,6 +37,24 @@ async function serve(patternlab, buildDir = 'public') {
3737

3838
// customize bs reload behavior based on the type of asset that's changed
3939
const filesToWatch = [
40+
{
41+
match: [`${process.cwd()}/patternlab-config.json`],
42+
fn: async function(event, filePath) {
43+
// when the main PL config changes, clear Node's cache (so the JSON config is re-read) and trigger another PL build
44+
// this allows config changes to show up without restarting the build!
45+
Object.keys(require.cache).forEach(function(key) {
46+
delete require.cache[key];
47+
});
48+
49+
const config = require(configPath);
50+
const pl = require('@pattern-lab/core')(config);
51+
52+
pl.build({
53+
watch: false,
54+
cleanPublic: true,
55+
});
56+
},
57+
},
4058
`${root}/**/*.css`,
4159
`${root}/**/*.js`,
4260
{

0 commit comments

Comments
 (0)