Socket
Socket
Sign inDemoInstall

apply-loader-after-first-build-webpack-plugin

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 1.0.0

README.md

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 @@ };

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc