Skip to content

Commit

Permalink
Adding ability to merge webpack configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulfair, Matt committed Oct 24, 2017
1 parent 09c1050 commit 07d1f6d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "edition-node-webpack",
"description": "A pure wrapper around patternlab-node core, the default pattern engine, and supporting frontend assets.",
"version": "1.0.1",
"version": "1.0.2",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"copy-webpack-plugin": "^4.0.1",
"event-hooks-webpack-plugin": "^1.0.0",
"glob": "^7.1.2",
"globby": "^6.1.0",
"patternlab-node": "^2.11.0",
"styleguidekit-assets-default": "^3.5.0",
"styleguidekit-mustache-default": "^3.0.0",
"webpack": "^3.5.6",
"webpack-config-utils": "^2.3.0"
"webpack-config-utils": "^2.3.0",
"webpack-merge": "^4.1.0"
},
"repository": "[email protected]:Comcast/patternlab-edition-node-webpack.git",
"bugs": "https://github.com/Comcast/patternlab-edition-node-webpack/issues",
Expand Down
6 changes: 4 additions & 2 deletions patternlab-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"paths": {
"source": {
"root": "./source/",
"app": "./source/_app",
"patterns": "./source/_patterns/",
"data": "./source/_data/",
"meta": "./source/_meta/",
Expand Down Expand Up @@ -66,11 +67,12 @@
"patternExportPatternPartials": [],
"patternExportDirectory": "./pattern_exports/",
"cacheBust": true,
"starterkitSubDir": "dist",
"starterkitPostInstallClean": false,
"outputFileSuffixes": {
"rendered": ".rendered",
"rawTemplate": "",
"markupOnly": ".markup-only"
},
"cleanOutputHtml": true
"cleanOutputHtml": true,
"exportToGraphViz": false
}
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The webpack wrapper around [Pattern Lab Node Core](https://github.com/pattern-la
## Installation and Starting

1. `yarn install` or `npm install`
2. `yarn start`
2. `yarn start` or `npm run start`


## Packaged Components
Expand Down Expand Up @@ -97,13 +97,14 @@ To install a specific StarterKit from GitHub type:
* [babel-preset-es2015](https://github.com/babel/babel/blob/master/LICENSE) - MIT
* [copy-webpack-plugin](https://github.com/webpack-contrib/copy-webpack-plugin/blob/master/LICENSE) - MIT
* [event-hooks-webpack-plugin](https://github.com/cascornelissen/event-hooks-webpack-plugin/blob/master/LICENSE.md) - MIT
* [glob](https://github.com/isaacs/node-glob/blob/master/LICENSE) - ISC
* [globby](https://github.com/sindresorhus/globby/blob/master/license) - MIT
* [patternlab-node](https://github.com/pattern-lab/patternlab-node/blob/master/LICENSE) - MIT
* [styleguidekit-assets-default](https://github.com/pattern-lab/styleguidekit-assets-default/blob/master/LICENSE) - MIT
* [styleguidekit-mustache-default](https://github.com/pattern-lab/styleguidekit-mustache-default/blob/master/LICENSE) - MIT
* [webpack](https://github.com/webpack/webpack/blob/master/LICENSE) - MIT
* [webpack-config-utils](https://github.com/kentcdodds/webpack-config-utils/blob/master/LICENSE) - MIT
* [webpack-dev-server](https://github.com/webpack/webpack-dev-server/blob/master/LICENSE) - MIT
* [webpack-merge](https://github.com/survivejs/webpack-merge/blob/master/LICENSE) - MIT
### Special Thanks and Contributions
Expand Down
Empty file removed source/_app/.gitkeep
Empty file.
8 changes: 7 additions & 1 deletion source/_app/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# _app

Used to store your app specific files.
Used to store your app specific files.

## Includes

**Custom Webpack Configuration**

`webpack.app.js` this file is used to place your custom webpack configuration. This will merge or override the values in `webpack.config.babel.js` This will provide a way to change your configuration and still get updates in the future.
10 changes: 10 additions & 0 deletions source/_app/webpack.app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const {getIfUtils} = require('webpack-config-utils');

module.exports = env => {
const {ifProd, ifDev} = getIfUtils(env);

const app = {
//Custom webpack configuration goes here
}
return app;
}
19 changes: 11 additions & 8 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
// webpack.config.js
const webpack = require('webpack');
const {resolve} = require('path');
const glob = require('glob');
const globby = require('globby');
const {getIfUtils, removeEmpty} = require('webpack-config-utils');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const EventHooksPlugin = require('event-hooks-webpack-plugin');
const plConfig = require('./patternlab-config.json');
const patternlab = require('patternlab-node')(plConfig);
const patternEngines = require('patternlab-node/core/lib/pattern_engines');

const merge = require('webpack-merge');
const customization = require(`${plConfig.paths.source.app}/webpack.app.js`);

module.exports = env => {
const {ifProd, ifDev} = getIfUtils(env);
const config = ({
const config = merge.smart(customization(env), {
devtool: ifDev('source-map'),
context: resolve(__dirname, 'source'),
node: {
fs: "empty"
},
entry: {
// Gathers any Source JS files and creates a bundle
//NOTE: This name can be changed, if so, make sure to update _meta/01-foot.mustache
"js/pl-source":
glob.sync(resolve(plConfig.paths.source.js + '**/*.js')).map(function (filePath) {
/**
* Gathers any Source JS files and creates a bundle
* Note: To change this, please modify _app/webpack.app.js and use the same key.
*/
"js/pl-source":
globby.sync([resolve(plConfig.paths.source.js + '**/*.js')]).map(function (filePath) {
return filePath;
})
},
Expand Down Expand Up @@ -121,7 +124,7 @@ module.exports = env => {
const allWatchFiles = watchFiles.concat(templateFilePaths);

allWatchFiles.forEach(function(globPath) {
const patternFiles = glob.sync(globPath).map(function (filePath) {
const patternFiles = globby.sync(globPath).map(function (filePath) {
return resolve(filePath);
});

Expand Down
8 changes: 7 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ glob@^6.0.4:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.2:
glob@^7.0.0, glob@^7.0.3, glob@^7.0.5:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
Expand Down Expand Up @@ -3812,6 +3812,12 @@ webpack-dev-server@^2.7.1:
webpack-dev-middleware "^1.11.0"
yargs "^6.6.0"

webpack-merge@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.0.tgz#6ad72223b3e0b837e531e4597c199f909361511e"
dependencies:
lodash "^4.17.4"

webpack-sources@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
Expand Down

0 comments on commit 07d1f6d

Please sign in to comment.