Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
invalidade cache if publicPath changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Jun 30, 2018
1 parent 7f42cf8 commit e91a1fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const wwp = 'webapp-webpack-plugin';
module.exports.run = ({prefix, favicons: options, logo, cache}, context, compilation) => {
// The entry file is just an empty helper
const filename = '[hash]';
const publicPath = compilation.outputOptions.publicPath;
const {publicPath = '/'} = compilation.outputOptions;

// Create an additional child compiler which takes the template
// and turns it into an Node.JS html factory.
// This allows us to use loaders during the compilation
const compiler = compilation.createChildCompiler(wwp, {filename, publicPath});
compiler.context = context;

const loader = `!${require.resolve('./loader')}?${JSON.stringify({prefix, options})}`;
const loader = `!${require.resolve('./loader')}?${JSON.stringify({prefix, options, path: publicPath})}`;

const cacheDirectory = cache && (
(typeof cache === 'string')
Expand Down
17 changes: 7 additions & 10 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@ const {parseQuery, interpolateName} = require('loader-utils');
const {getContext} = require('./compat');

const trailingSlash = (path) => (path.substr(-1) !== '/') ? path + '/' : path;
const getPublicPath = ({outputOptions: {publicPath = '/'}}) => publicPath && trailingSlash(publicPath);

module.exports = function (content) {
/* istanbul ignore next */
if (!this.async) throw new Error('async is required');

const {prefix, options} = parseQuery(this.query);

const callback = this.async();
const context = getContext(this);
const publicPath = getPublicPath(this._compilation);
const path = prefix && trailingSlash(interpolateName(this, prefix, {
context,
content: msgpack.encode([content, options]), // hash must depend on logo + config
const query = parseQuery(this.query);
const path = query.path && trailingSlash(query.path);
const prefix = query.prefix && trailingSlash(interpolateName(this, query.prefix, {
context: getContext(this),
content: msgpack.encode([content, query.options]), // hash must depend on logo + config
}));

// Generate icons
return favicons(content, Object.assign(options, {path: url.resolve(publicPath, path)}))
return favicons(content, Object.assign(query.options, {path: url.resolve(path, prefix)}))
.then(result => {
const html = result.html.join('');
const assets = [...result.images, ...result.files].map(({name, contents}) => ({name: path + name, contents}));
const assets = [...result.images, ...result.files].map(({name, contents}) => ({name: prefix + name, contents}));

return callback(null, 'module.exports = ' + JSON.stringify(msgpack.encode({html, assets}).toString('base64')));
})
Expand Down

0 comments on commit e91a1fe

Please sign in to comment.