Skip to content

Commit

Permalink
docs(demo-apps): fix webpack bundling
Browse files Browse the repository at this point in the history
ng-table is incorrectly being added to main bundle
  • Loading branch information
ccrowhurstram committed Dec 4, 2016
1 parent 50d3cdf commit 9ca75ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions demo-apps/es6-webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ module.exports = (env = { prod: false, debug: false, port: 8080, host: 'localhos
'vendor-styles': path.join(__dirname, 'src', 'shared', 'vendor-styles.scss')
}
};

return merge(
{
entry: {
main: path.join(__dirname, 'src', 'main.js')
}
},
parts.asAppBundle(),
parts.asAppBundle({
vendorSelector: parts.isNotAppModuleSelector
}),
vendorStyles,
parts.isDevServer ? parts.sass() : parts.extractSassChunks(vendorStyles.entry),
parts.es6(),
Expand Down
3 changes: 3 additions & 0 deletions demo-apps/ts-webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = (env = { prod: false, debug: false, port: 8080, host: 'localhos
main: path.join(__dirname, 'src', 'main.ts')
}
},
parts.asAppBundle({
vendorSelector: parts.isNotAppModuleSelector
}),
parts.asAppBundle(),
extactedStyles,
parts.isDevServer ? parts.sass() : parts.extractSassChunks(extactedStyles.entry),
Expand Down
14 changes: 11 additions & 3 deletions scripts/webpack/appParts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ function createAppParts(rootDir, env = {}) {
const loadCssWithSourceMaps = ['css-loader?sourceMap', 'resolve-url-loader', 'sass-loader?sourceMap'];
const loadCss = ['css-loader', 'resolve-url-loader', 'sass-loader?sourceMap'];

const isNodeModuleSelector = (function () {
const isNodeModule = new RegExp('node_modules');
return (module) => isNodeModule.test(module.resource);
})();

return Object.assign({}, commonParts, {
asAppBundle,
extractSassChunks,
inlineImages,
inlineHtmlTemplates,
inlineNgTableHtmlTemplates,
isDevServer,
isNotAppModuleSelector,
sass,
useHtmlPlugin
});

/////


function asAppBundle() {
const isNodeModule = new RegExp('node_modules');
function asAppBundle({ vendorSelector = isNodeModuleSelector } = {}) {

const common = merge(
{
Expand All @@ -47,7 +52,7 @@ function createAppParts(rootDir, env = {}) {
// include node_modules requested in a seperate bundle
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: module => isNodeModule.test(module.resource)
minChunks: vendorSelector
}),
// extract webpack manifest file into it's own chunk to ensure vendor hash does not change
// (as per solution discussed here https://github.com/webpack/webpack/issues/1315)
Expand Down Expand Up @@ -102,6 +107,9 @@ function createAppParts(rootDir, env = {}) {
};
}

function isNotAppModuleSelector(module) {
return !(module.resource && module.resource.startsWith(rootDir));
}

function useHtmlPlugin() {
var HtmlWebpackPlugin = require('html-webpack-plugin');
Expand Down

0 comments on commit 9ca75ad

Please sign in to comment.