Skip to content

Commit

Permalink
feat: added shared bundles configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Mar 25, 2021
1 parent 0810d9d commit 7c0a23b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 33 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## [2.0.5](https://github.com/hayes0724/shopify-packer/compare/2.0.4...2.0.5) (2021-03-25)


### :art: Styles

* eslint and prettier issues fixed ([7c81a7c](https://github.com/hayes0724/shopify-packer/commit/7c81a7c9e41371f2378fce4e1812cf7b6504872f))


### :bug: Bug Fixes

* replace all special charcters in script names ([ce3da66](https://github.com/hayes0724/shopify-packer/commit/ce3da66879da16e88636e437f95eeea90528e48c))


### :sparkles: Features

* added default cache group ([0810d9d](https://github.com/hayes0724/shopify-packer/commit/0810d9dee94943809b7af17dd8e7e8c258607b1b))
* added shared bundles configuration ([c082182](https://github.com/hayes0724/shopify-packer/commit/c08218264a5ac930eb98f8597838b02247f0b25b))


### chore

* eslint and prettier config for packer development ([797493a](https://github.com/hayes0724/shopify-packer/commit/797493a8ed8ecdafcdedaf10e83931e96ad21b39))



## [2.0.4](https://github.com/hayes0724/shopify-packer/compare/2.0.3...2.0.4) (2021-03-24)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hayes0724/shopify-packer",
"version": "2.0.4",
"version": "2.0.5",
"bin": {
"packer": "cli/index.js"
},
Expand Down
1 change: 1 addition & 0 deletions packer.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
'network.external': '',
'network.interface': '',
'network.reload': 0,
'build.sharedBundles': true,
};
44 changes: 12 additions & 32 deletions src/webpack/config/prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@ const {merge} = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const IncludeLiquidStylesPlugin = require('../include-liquid-styles');

const PackerConfig = require('../../config');
const config = new PackerConfig(require('../../../packer.schema'));

const development = false;
process.env.NODE_ENV = 'production';
const getChunkName = require('../../utilities/get-chunk-name');
const {customConfigCheck} = require('../custom');
const getLayoutEntrypoints = require('../../utilities/get-layout-entrypoints');
const getTemplateEntrypoints = require('../../utilities/get-template-entrypoints');
const {customConfigCheck} = require('../custom');
config.set('files.layout', getLayoutEntrypoints());
config.set('files.template', getTemplateEntrypoints());

// Parts
const core = require('../parts/core');
const css = require('../parts/css');
const scss = require('../parts/scss');

const optimization = require('../parts/optimization');
const mergeProd = customConfigCheck(config.get('merge.prod'));
config.set('layoutEntrypoints', getLayoutEntrypoints());
config.set('templateEntrypoints', getTemplateEntrypoints());

core.entry = {
...config.get('layoutEntrypoints'),
...config.get('templateEntrypoints'),
...config.get('files.layout'),
...config.get('files.template'),
...config.get('entrypoints'),
};

Expand All @@ -36,6 +34,7 @@ const output = merge([
{
mode: 'production',
devtool: false,
optimization: optimization,
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
Expand All @@ -58,8 +57,8 @@ const output = merge([
preserveLineBreaks: true,
},
isDevServer: development,
liquidTemplates: config.get('templateEntrypoints'),
liquidLayouts: config.get('layoutEntrypoints'),
liquidTemplates: config.get('files.template'),
liquidLayouts: config.get('files.layout'),
}),

new HtmlWebpackPlugin({
Expand All @@ -74,30 +73,11 @@ const output = merge([
preserveLineBreaks: true,
},
isDevServer: development,
liquidTemplates: config.get('templateEntrypoints'),
liquidLayouts: config.get('layoutEntrypoints'),
liquidTemplates: config.get('files.template'),
liquidLayouts: config.get('files.layout'),
}),
new IncludeLiquidStylesPlugin(),
],
optimization: {
nodeEnv: 'production',
minimize: true,
splitChunks: {
cacheGroups: {
defaultVendors: false,
vendor: {
test: /[\\/]node_modules[\\/]/,
name: getChunkName,
chunks: 'initial',
},
default: {
test: /[\\/]src[\\/]/,
name: getChunkName,
chunks: 'initial',
},
},
},
},
},
mergeProd,
]);
Expand Down
28 changes: 28 additions & 0 deletions src/webpack/parts/optimization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const getChunkName = require('../../utilities/get-chunk-name');
const PackerConfig = require('../../config');
const config = new PackerConfig(require('../../../packer.schema'));

const optimization = {
nodeEnv: 'production',
minimize: true,
splitChunks: {
cacheGroups: {
defaultVendors: false,
vendor: {
test: /[\\/]node_modules[\\/]/,
name: getChunkName,
chunks: 'initial',
priority: 5,
},
},
},
};

if (config.get('build.sharedBundles')) {
optimization.splitChunks.cacheGroups.default = {
name: getChunkName,
chunks: 'all',
};
}

module.exports = optimization;

0 comments on commit 7c0a23b

Please sign in to comment.