Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with deprecated webpack API #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ function DynamicPublicPathPlugin(options) {
DynamicPublicPathPlugin.prototype.apply = function(compiler) {

if(this.options && this.options.externalGlobal && this.options.chunkName) {
compiler.plugin('after-emit', (compilation, callback) => {

compiler.hooks.afterEmit.tap({name: 'DynamicPublicPathPlugin'}, (compilation) => {
this.compilation = compilation;

if(compilation.options.output && compilation.options.output.publicPath){
this.publicPathStr = '"' + compilation.options.output.publicPath + '"';
}else{
this.err('output.publicPath must be defined in webpack config ' +
'(used only as placeholder, make it distinctive)');
callback();
return;
}

Expand All @@ -57,7 +55,6 @@ DynamicPublicPathPlugin.prototype.apply = function(compiler) {

if(!chunk){
this.err('chunk "'+this.options.chunkName+'" does not exist.');
callback();
return;
}

Expand All @@ -68,7 +65,7 @@ DynamicPublicPathPlugin.prototype.apply = function(compiler) {

filePath = path.resolve(compilation.assets[fileName].existsAt);

this.doReplace(filePath, callback);
this.doReplace(filePath);
});
}else{
this.err('params missing: \n[mandatory] externalGlobal - name of global var you want to use as publicPath.\n[mandatory] chunkName - name of chunk in which to look for publicPath references.');
Expand All @@ -79,9 +76,8 @@ DynamicPublicPathPlugin.prototype.apply = function(compiler) {
* Opens file and replaces content.
*
* @param {string} filePath
* @param {function} callback
*/
DynamicPublicPathPlugin.prototype.doReplace = function(filePath, callback){
DynamicPublicPathPlugin.prototype.doReplace = function(filePath){
this.log('attempting to modify: ' + filePath);

// open file
Expand All @@ -90,7 +86,6 @@ DynamicPublicPathPlugin.prototype.doReplace = function(filePath, callback){
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
_log('fs read error (' + err + ')');
callback();
return;
}

Expand All @@ -104,13 +99,10 @@ DynamicPublicPathPlugin.prototype.doReplace = function(filePath, callback){
} else {
this.log('replaced publicPath');
}

callback();
});
});
} else {
this.err('could not find file (' + filePath + ')');
callback();
}
});
};
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": "dynamic-public-path-webpack-plugin",
"version": "1.0.2",
"version": "1.0.3",
"description": "Use global, client side variable to set publicPath instead of string set options.publicPath",
"main": "index.js",
"scripts": {
Expand Down