apply-loader-after-first-build-webpack-plugin
Advanced tools
Comparing version 0.0.1 to 1.0.0
66
index.js
@@ -1,13 +0,24 @@ | ||
var pluginOptions; | ||
var startingLoaderLength; | ||
var newLoadersConcatted = false; | ||
function ApplyLoaderAfterFirstBuildPlugin(options) { | ||
pluginOptions = options || {}; | ||
this.pluginOptions = options || {}; | ||
this.newLoadersConcatted = false; | ||
this.startingLoaderLength = 0; | ||
this.startingPreLoaderLength = 0; | ||
this.startingPostLoaderLength = 0; | ||
this.startTime = Date.now(); | ||
this.prevTimestamps = {}; | ||
this.addedIncludes = {}; | ||
var that = this; | ||
this.addNewIncludes = function(loaders, newFiles, typeKey) { | ||
for (var i = that[typeKey]; i < loaders.length; i++) { | ||
var loader = loaders[i]; | ||
loader.include = loader.include ? loader.include.concat(newFiles) : newFiles; | ||
} | ||
} | ||
} | ||
ApplyLoaderAfterFirstBuildPlugin.prototype.apply = function(compiler) { | ||
var newLoaders = pluginOptions.loaders; | ||
var newPreLoaders = pluginOptions.preLoaders; | ||
var newPostLoaders = pluginOptions.postLoaders; | ||
var that = this; | ||
var newLoaders = this.pluginOptions.loaders; | ||
var newPreLoaders = this.pluginOptions.preLoaders; | ||
var newPostLoaders = this.pluginOptions.postLoaders; | ||
@@ -24,7 +35,37 @@ var hasNewLoaders = newLoaders && Array.isArray(newLoaders); | ||
var startingPostLoaders = compiler.options.module.postLoaders; | ||
this.startingLoaderLength = startingLoaders ? startingLoaders.length : 0; | ||
this.startingPreLoaderLength = startingPreLoaders ? startingPreLoaders.length : 0; | ||
this.startingPostLoaderLength = startingPostLoaders ? startingPostLoaders.length : 0; | ||
compiler.plugin('make', function(compilation, callback) { | ||
if (that.newLoadersConcatted) { | ||
var newFiles = Object.keys(compilation.fileTimestamps).filter(function(fileName) { | ||
var timestamp = compilation.fileTimestamps[fileName]; | ||
var prevTimestamp = that.prevTimestamps[fileName] || that.startTime; | ||
if (timestamp > prevTimestamp && !that.addedIncludes[fileName]) { | ||
that.addedIncludes[fileName] = true; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
if (hasNewLoaders && newFiles.length) { | ||
that.addNewIncludes(compiler.options.module.loaders, newFiles, "startingLoaderLength"); | ||
} | ||
if (hasNewPreLoaders && newFiles.length) { | ||
that.addNewIncludes(compiler.options.module.preLoaders, newFiles, "startingPreLoaderLength"); | ||
} | ||
if (hasNewPostLoaders && newFiles.length) { | ||
that.addNewIncludes(compiler.options.module.postLoaders, newFiles, "startingPostLoaderLength"); | ||
} | ||
that.prevTimestamps = compilation.fileTimestamps | ||
} | ||
callback(); | ||
//do something to update the incldues of the dynamically added loaders here before hcanged files are run | ||
}); | ||
compiler.plugin('done', function() { | ||
if (newLoadersConcatted) { | ||
if (that.newLoadersConcatted) { | ||
return; | ||
} | ||
if (startingLoaders && hasNewLoaders) { | ||
@@ -43,3 +84,3 @@ compiler.options.module.loaders = startingLoaders.concat(newLoaders); | ||
if (startingPostLoaders && hasNewPostLoaders) { | ||
compiler.options.module.preLoaders = startingPostLoaders.concat(newPostLoaders); | ||
compiler.options.module.postLoaders = startingPostLoaders.concat(newPostLoaders); | ||
} else if (hasNewPostLoaders) { | ||
@@ -49,4 +90,3 @@ compiler.options.module.postLoaders = newPostLoaders; | ||
newLoadersConcatted = true; | ||
that.newLoadersConcatted = true; | ||
}); | ||
@@ -53,0 +93,0 @@ }; |
{ | ||
"name": "apply-loader-after-first-build-webpack-plugin", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "a webpack plugin that allows you to dynamically add a loader after the initial build has occurred (useful when using watch)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5647
4
81
2
1
41