Skip to content

Commit

Permalink
fix: updated development asset handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Mar 29, 2021
1 parent 9b1f640 commit b0213b7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [2.0.11](https://github.com/hayes0724/shopify-packer/compare/2.0.10...2.0.11) (2021-03-29)


### :bug: Bug Fixes

* updated development asset handling ([e6ccf99](https://github.com/hayes0724/shopify-packer/commit/e6ccf99005e5f7ec05c074c1e35c56b66c5daa5a))



## [2.0.10](https://github.com/hayes0724/shopify-packer/compare/2.0.9...2.0.10) (2021-03-28)


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hayes0724/shopify-packer",
"version": "2.0.10",
"version": "2.0.11",
"bin": {
"packer": "cli/index.js"
},
Expand Down Expand Up @@ -63,7 +63,7 @@
"minimist": "^1.2.5",
"ora": "^5.4.0",
"portscanner": "^2.2.0",
"postcss": "^8.2.8",
"postcss": "^7.0.35",
"postcss-loader": "^5.2.0",
"prettier": "^2.1.2",
"sass": "^1.32.8",
Expand Down
2 changes: 1 addition & 1 deletion src/config/common-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
module.exports = {
root: process.cwd(),
package: (config) => path.join(config.get('root'), 'package.json'),
commonExcludes: [/node_modules/, /assets\/static/],
commonExcludes: [/node_modules/, /assets\/static/, /\.gitkeep$/],
cache: (config) => path.join(config.get('root'), '.cache'),
'packer.config': (config) =>
path.join(config.get('root'), 'packer.config.js'),
Expand Down
18 changes: 11 additions & 7 deletions src/server/asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ module.exports = class AssetServer {
file.replace(`..${path.sep}`, '').replace(`../`, '')
);
}
if (
!this._isLiquidFile(file) &&
!isHotUpdateFile(file) &&
!file.includes('.js') &&
this._hasAssetChanged(file, info)
) {
return this.updates.add(file.replace('../', ''));
if (this._isAssetFile(file) && this._hasAssetChanged(file, info)) {
return this.updates.add(`assets/${file}`);
}
}

Expand Down Expand Up @@ -104,6 +99,15 @@ module.exports = class AssetServer {
);
}

_isAssetFile(file) {
return (
!this._isLiquidFile(file) &&
!isHotUpdateFile(file) &&
!file.includes('.js') &&
!file.includes('.gitkeep')
);
}

_hasAssetChanged(key, info) {
const oldHash = this.assetHashes.get(key);
const newHash = this._updateAssetHash(key, info);
Expand Down
18 changes: 2 additions & 16 deletions src/webpack/config/dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {customConfigCheck} = require('../custom');
const core = require('../parts/core');
const css = require('../parts/css');
const scss = require('../parts/scss');
const assets = require('../parts/assets');
const liquidStyles = require('../parts/liquid-styles');
const copy = require('../parts/copy');

Expand All @@ -35,6 +36,7 @@ Object.keys(core.entry).forEach((name) => {
module.exports = merge([
liquidStyles,
core,
assets,
scss,
css,
copy,
Expand All @@ -52,22 +54,6 @@ module.exports = merge([
exclude: config.get('commonExcludes'),
loader: path.resolve(__dirname, '../hmr-alamo-loader.js'),
},
{
test: /\.(eot|ttf|woff|woff2|otf)$/,
exclude: config.get('commonExcludes'),
type: 'asset',
generator: {
filename: '[name].[ext]',
},
},
{
test: /\.(png|svg|jpg|gif)$/,
exclude: config.get('commonExcludes'),
type: 'asset',
generator: {
filename: '[name].[ext]',
},
},
],
},
plugins: [
Expand Down
2 changes: 2 additions & 0 deletions src/webpack/config/prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config.set('files.template', getTemplateEntrypoints());
const core = require('../parts/core');
const css = require('../parts/css');
const scss = require('../parts/scss');
const assets = require('../parts/assets');
const clean = require('../parts/clean');
const copy = require('../parts/copy');
const optimization = require('../parts/optimization');
Expand All @@ -33,6 +34,7 @@ core.entry = {
const output = merge([
liquidStyles,
core,
assets,
scss,
css,
clean,
Expand Down
27 changes: 27 additions & 0 deletions src/webpack/parts/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const PackerConfig = require('../../config');
const config = new PackerConfig(require('../../../packer.schema'));

const assets = {
module: {
rules: [
{
test: /\.(eot|ttf|woff|woff2|otf)$/,
exclude: config.get('commonExcludes'),
type: 'asset/resource',
generator: {
filename: '../[name][ext]',
},
},
{
test: /\.(png|svg|jpg|gif)$/,
exclude: config.get('commonExcludes'),
type: 'asset/resource',
generator: {
filename: '../[name][ext]',
},
},
],
},
};

module.exports = assets;

0 comments on commit b0213b7

Please sign in to comment.