Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Simplify assets
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kelly committed Oct 22, 2018
1 parent d3c5c91 commit 7aa6f2f
Show file tree
Hide file tree
Showing 17 changed files with 404 additions and 382 deletions.
13 changes: 0 additions & 13 deletions packages/html-webpack-liquid-asset-tags-plugin/README.md

This file was deleted.

42 changes: 0 additions & 42 deletions packages/html-webpack-liquid-asset-tags-plugin/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions packages/html-webpack-liquid-asset-tags-plugin/package.json

This file was deleted.

23 changes: 12 additions & 11 deletions packages/slate-config/common/paths.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ module.exports = {
// Source directory of theme
'paths.theme.src': (config) => path.join(config.get('paths.theme'), 'src'),

'paths.theme.src.assets': (config) =>
path.join(config.get('paths.theme.src'), 'assets'),

// Source of theme configuration files
'paths.theme.src.config': (config) =>
path.join(config.get('paths.theme.src'), 'config'),

// Source font directory for theme
'paths.theme.src.fonts': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'fonts'),

// Source of images directory
'paths.theme.src.images': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'images'),

// Source of theme liquid layout files
'paths.theme.src.layouts': (config) =>
path.join(config.get('paths.theme.src'), 'layout'),
Expand All @@ -37,15 +32,15 @@ module.exports = {

// Source scripts directory for theme
'paths.theme.src.scripts': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'scripts'),
path.join(config.get('paths.theme.src'), 'scripts'),

// Source snippets directory
'paths.theme.src.snippets': (config) =>
path.join(config.get('paths.theme.src'), 'snippets'),

// Static asset directory for files that statically copied to paths.theme.dist.assets
'paths.theme.src.static': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'static'),
'paths.theme.src.sections': (config) =>
path.join(config.get('paths.theme.src'), 'sections'),

// Main SVG source directory for theme
'paths.theme.src.svgs': (config) =>
Expand Down Expand Up @@ -78,6 +73,12 @@ module.exports = {
'paths.theme.dist.locales': (config) =>
path.join(config.get('paths.theme.dist'), 'locales'),

'paths.theme.dist.sections': (config) =>
path.join(config.get('paths.theme.dist'), 'sections'),

'paths.theme.dist.templates': (config) =>
path.join(config.get('paths.theme.dist'), 'templates'),

// Directory for storing all temporary and/or cache files
'paths.theme.cache': (config) =>
path.join(config.get('paths.theme'), '.cache'),
Expand Down
3 changes: 0 additions & 3 deletions packages/slate-liquid-asset-loader/README.md

This file was deleted.

76 changes: 0 additions & 76 deletions packages/slate-liquid-asset-loader/index.js

This file was deleted.

17 changes: 0 additions & 17 deletions packages/slate-liquid-asset-loader/package.json

This file was deleted.

2 changes: 2 additions & 0 deletions packages/slate-sync/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ module.exports = {
return Promise.reject(new Error('No files to deploy.'));
}

console.log(files);

filesToDeploy = [...new Set([...filesToDeploy, ...files])];

return maybeDeploy();
Expand Down
4 changes: 1 addition & 3 deletions packages/slate-tools/slate-tools.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@ module.exports = {
'webpack.cssnano.settings': {zindex: false, reduceIdents: false},

// Object which contains entrypoints used in webpack's config.entry key
'webpack.entrypoints': {
static: path.resolve(__dirname, 'tools/webpack/static-files-glob.js'),
},
'webpack.entrypoints': {},
};
1 change: 1 addition & 0 deletions packages/slate-tools/tools/asset-server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = class App {
app.webpackDevMiddleware = webpackDevMiddleware(compiler, {
logLevel: 'silent',
reload: true,
writeToDisk: true,
});
app.webpackHotMiddleware = webpackHotMiddleware(compiler, {
log: false,
Expand Down
29 changes: 25 additions & 4 deletions packages/slate-tools/tools/asset-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = class DevServer {
}/`;

this.assetHashes = {};
this.chunkHashes = {};
this.domain = options.domain;
this.options = options;
this.port = options.port;
Expand Down Expand Up @@ -48,7 +49,7 @@ module.exports = class DevServer {
}

_onCompileDone(stats) {
const files = this._getChangedLiquidFiles(stats);
const files = this._getChangedFiles(stats);

return this.client.sync(files);
}
Expand All @@ -60,20 +61,40 @@ module.exports = class DevServer {
});
}

_getChangedLiquidFiles(stats) {
_getChangedFiles(stats) {
const assets = Object.entries(stats.compilation.assets);
const allChunks = stats.compilation.chunks;

return (
assets
.filter(([key, asset]) => {
const matchedChunks = allChunks.filter((chunk) => {
return key.indexOf(chunk.id) > -1;
});

const changedChunks = matchedChunks.filter((chunk) => {
const oldChunkHash = this.chunkHashes[chunk.id];
this.chunkHashes[chunk.id] = chunk.hash;

return oldChunkHash !== chunk.hash;
});

const oldHash = this.assetHashes[key];
const newHash = this._updateAssetHash(key, asset);
let hasChanged;

if (matchedChunks.length > 0) {
hasChanged = changedChunks.length > 0;
} else {
hasChanged = oldHash !== newHash;
}

return (
asset.emitted &&
(/\.liquid$/.test(key) || /\.json$/.test(key)) &&
!/\.hot-update\.json$/.test(key) &&
!/\.hot-update\.js$/.test(key) &&
fs.existsSync(asset.existsAt) &&
oldHash !== newHash
hasChanged
);
})
/* eslint-disable-next-line no-unused-vars */
Expand Down
17 changes: 1 addition & 16 deletions packages/slate-tools/tools/webpack/config/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ module.exports = merge([

devtool: '#eval-source-map',

module: {
rules: [
{
test: /^(?:(?!(css|scss|sass)).)*\.(liquid)$/,
exclude: config.get('webpack.commonExcludes'),
use: [
{loader: 'extract-loader'},
{
loader: '@shopify/slate-liquid-asset-loader',
options: {devServer: true},
},
],
},
],
},

plugins: [
new webpack.HotModuleReplacementPlugin(),

Expand Down Expand Up @@ -80,6 +64,7 @@ module.exports = merge([
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency',
isDevServer: true,
liquidTemplates: getTemplateEntrypoints(),
liquidLayouts: getLayoutEntrypoints(),
}),
Expand Down
Loading

0 comments on commit 7aa6f2f

Please sign in to comment.