webpack-manifest-resource-plugin
Advanced tools
Comparing version 4.2.4 to 4.2.5
4.2.5 / 2018-11-05 | ||
================== | ||
* fix: javascript heap out of memory https://github.com/easy-team/easywebpack/issues/26 | ||
4.2.2 / 2018-03-29 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -5,5 +5,5 @@ var path = require('path'); | ||
var _ = require('lodash'); | ||
var mutexify = require('mutexify'); | ||
// var mutexify = require('mutexify'); | ||
var lock = mutexify(); | ||
// var lock = mutexify(); | ||
@@ -25,2 +25,3 @@ function ManifestPlugin(opts) { | ||
}, opts || {}); | ||
this.isRunned = false; | ||
} | ||
@@ -72,3 +73,3 @@ | ||
ManifestPlugin.prototype.getDeps = function(compiler, manifest, commonsChunk) { | ||
ManifestPlugin.prototype.getDeps = function(webpackConfig, manifest, commonsChunk) { | ||
const deps = {}; | ||
@@ -85,3 +86,2 @@ const commonChunkScript = []; | ||
}); | ||
const webpackConfig = compiler.options; | ||
const entryNames = Object.keys(webpackConfig.entry); | ||
@@ -114,3 +114,3 @@ entryNames.forEach(entryName => { | ||
ManifestPlugin.prototype.getResource = function(compiler, manifest, publicPath) { | ||
ManifestPlugin.prototype.getResource = function(webpackConfig, manifest, publicPath) { | ||
const buildPath = this.opts.buildPath.replace(this.opts.baseDir, '').replace(/^\//, ''); | ||
@@ -155,3 +155,3 @@ const normalizeManifest = this.normalize(manifest); | ||
publicPath = this.opts.proxy ? publicPath.replace(this.opts.host, '') : publicPath; | ||
const depsManifest = this.getDeps(compiler, normalizeManifest, commonsChunk); | ||
const depsManifest = this.getDeps(webpackConfig, normalizeManifest, commonsChunk); | ||
return Object.assign({}, normalizeManifest, { | ||
@@ -164,170 +164,159 @@ deps: depsManifest, | ||
ManifestPlugin.prototype.apply = function(compiler) { | ||
ManifestPlugin.prototype.emit = function(moduleAsset, compilation, compileCallback) { | ||
var seed = this.opts.seed || {}; | ||
var moduleAssets = {}; | ||
var moduleAsset = function (module, file) { | ||
moduleAssets[file] = path.join( | ||
path.dirname(file), | ||
path.basename(module.userRequest) | ||
); | ||
}; | ||
var emit = function(compilation, compileCallback) { | ||
var publicPath = compilation.options.output.publicPath; | ||
var stats = compilation.getStats().toJson(); | ||
var files = compilation.chunks.reduce(function(files, chunk) { | ||
return chunk.files.reduce(function(files, path) { | ||
var name = chunk.name ? chunk.name : null; | ||
if (name) { | ||
name = name + '.' + this.getFileType(path); | ||
} else { | ||
// For nameless chunks, just map the files directly. | ||
name = path; | ||
} | ||
// Webpack 4: .isOnlyInitial() | ||
// Webpack 3: .isInitial() | ||
// Webpack 1/2: .initial | ||
return files.concat({ | ||
path: path, | ||
chunk: chunk, | ||
name: name, | ||
isInitial: chunk.isOnlyInitial ? chunk.isOnlyInitial() : (chunk.isInitial ? chunk.isInitial() : chunk.initial), | ||
isChunk: true, | ||
isAsset: false, | ||
isModuleAsset: false | ||
}); | ||
}.bind(this), files); | ||
}.bind(this), []); | ||
// module assets don't show up in assetsByChunkName. | ||
// we're getting them this way; | ||
files = stats.assets.reduce(function(files, asset) { | ||
var name = moduleAssets[asset.name]; | ||
var webpackConfig = compilation.options; | ||
var publicPath = webpackConfig.output.publicPath; | ||
var files = compilation.chunks.reduce((files, chunk) => { | ||
return chunk.files.reduce((files, path) => { | ||
var name = chunk.name ? chunk.name : null; | ||
if (name) { | ||
return files.concat({ | ||
path: asset.name, | ||
name: name, | ||
isInitial: false, | ||
isChunk: false, | ||
isAsset: true, | ||
isModuleAsset: true | ||
}); | ||
name = name + '.' + this.getFileType(path); | ||
} else { | ||
// For nameless chunks, just map the files directly. | ||
name = path; | ||
} | ||
var isEntryAsset = asset.chunks.length > 0; | ||
if (isEntryAsset) { | ||
return files; | ||
} | ||
// Webpack 4: .isOnlyInitial() | ||
// Webpack 3: .isInitial() | ||
// Webpack 1/2: .initial | ||
return files.concat({ | ||
path: asset.name, | ||
name: asset.name, | ||
isInitial: false, | ||
isChunk: false, | ||
isAsset: true, | ||
path: path, | ||
chunk: chunk, | ||
name: name, | ||
isChunk: true, | ||
isAsset: false, | ||
isModuleAsset: false | ||
}); | ||
}, files); | ||
}, []); | ||
files = files.filter(function(file) { | ||
// Don't add hot updates to manifest | ||
return file.path.indexOf('hot-update') === -1; | ||
// module assets don't show up in assetsByChunkName. | ||
// we're getting them this way; | ||
files = Object.keys(compilation.assets).reduce((files, name) => { | ||
const mName = moduleAsset[name]; | ||
return files.concat({ | ||
path: name, | ||
name: mName || name, | ||
isInitial: false, | ||
isChunk: false, | ||
isAsset: true, | ||
isModuleAsset: !!mName | ||
}); | ||
}, files); | ||
// Append optional basepath onto all references. | ||
// This allows output path to be reflected in the manifest. | ||
if (this.opts.basePath) { | ||
files = files.map(function(file) { | ||
file.name = this.opts.basePath + file.name; | ||
return file; | ||
}.bind(this)); | ||
} | ||
files = files.filter(file => { | ||
// Don't add hot updates to manifest | ||
return file.path.indexOf('hot-update') === -1; | ||
}); | ||
if (publicPath) { | ||
// Similar to basePath but only affects the value (similar to how | ||
// output.publicPath turns require('foo/bar') into '/public/foo/bar', see | ||
// https://github.com/webpack/docs/wiki/configuration#outputpublicpath | ||
files = files.map(function(file) { | ||
file.path = publicPath + file.path; | ||
return file; | ||
}.bind(this)); | ||
} | ||
// Append optional basepath onto all references. | ||
// This allows output path to be reflected in the manifest. | ||
if (this.opts.basePath) { | ||
files = files.map(file => { | ||
file.name = this.opts.basePath + file.name; | ||
return file; | ||
}); | ||
} | ||
if (publicPath) { | ||
// Similar to basePath but only affects the value (similar to how | ||
// output.publicPath turns require('foo/bar') into '/public/foo/bar', see | ||
// https://github.com/webpack/docs/wiki/configuration#outputpublicpath | ||
files = files.map(file => { | ||
file.name = file.name.replace(/\\/g, '/'); | ||
file.path = file.path.replace(/\\/g, '/'); | ||
file.path = publicPath + file.path; | ||
return file; | ||
}); | ||
} | ||
if (this.opts.filter) { | ||
files = files.filter(this.opts.filter); | ||
} | ||
files = files.map(file => { | ||
file.name = file.name.replace(/\\/g, '/'); | ||
file.path = file.path.replace(/\\/g, '/'); | ||
return file; | ||
}); | ||
if (this.opts.map) { | ||
files = files.map(this.opts.map); | ||
} | ||
if (this.opts.filter) { | ||
files = files.filter(this.opts.filter); | ||
} | ||
if (this.opts.sort) { | ||
files = files.sort(this.opts.sort); | ||
} | ||
if (this.opts.map) { | ||
files = files.map(this.opts.map); | ||
} | ||
var manifest; | ||
if (this.opts.generate) { | ||
manifest = this.opts.generate(seed, files); | ||
} else { | ||
manifest = files.reduce(function(manifest, file) { | ||
manifest[file.name] = file.path; | ||
return manifest; | ||
}, seed); | ||
} | ||
if (this.opts.sort) { | ||
files = files.sort(this.opts.sort); | ||
} | ||
var resource = this.getResource(compiler, manifest, publicPath); | ||
var json = JSON.stringify(resource, null, 2); | ||
var outputFolder = compilation.options.output.path; | ||
var outputFile = this.opts.filepath ? this.opts.filepath : path.resolve(compilation.options.output.path, this.opts.fileName); | ||
var outputName = this.opts.filepath ? path.basename(this.opts.filepath) : path.relative(outputFolder, outputFile); | ||
var manifest; | ||
if (this.opts.generate) { | ||
manifest = this.opts.generate(seed, files); | ||
} else { | ||
manifest = files.reduce((manifest, file) => { | ||
manifest[file.name] = file.path; | ||
return manifest; | ||
}, seed); | ||
} | ||
if (this.opts.assets) { | ||
compilation.assets[outputName] = { | ||
source: function() { | ||
return json; | ||
}, | ||
size: function() { | ||
return json.length; | ||
} | ||
}; | ||
} | ||
var resource = this.getResource(webpackConfig, manifest, publicPath); | ||
var json = JSON.stringify(resource, null, 2); | ||
var outputFolder = webpackConfig.output.path; | ||
var outputFile = this.opts.filepath ? this.opts.filepath : path.resolve(compilation.options.output.path, this.opts.fileName); | ||
var outputName = this.opts.filepath ? path.basename(this.opts.filepath) : path.relative(outputFolder, outputFile); | ||
if (this.opts.writeToFileEmit) { | ||
fse.outputFileSync(outputFile, json); | ||
if (this.opts.assets) { | ||
compilation.assets[outputName] = { | ||
source: function() { | ||
return json; | ||
}, | ||
size: function() { | ||
return json.length; | ||
} | ||
}; | ||
} | ||
if (this.opts.writeToFileEmit) { | ||
fse.outputFileSync(outputFile, json); | ||
} | ||
// NOTE: make sure webpack is not writing multiple manifests simultaneously | ||
// lock(function(release) { | ||
// if (compiler.hooks) { | ||
// compiler.hooks.afterEmit.tap('ManifestResourcePlugin', compilation => { | ||
// release(); | ||
// }); | ||
// } else { | ||
// compiler.plugin('after-emit', (compilation, cb) => { | ||
// release(); | ||
// cb(); | ||
// }); | ||
// compilation.applyPluginsAsync('webpack-manifest-resource-plugin-after-emit', manifest, compileCallback); | ||
// } | ||
// }); | ||
}; | ||
ManifestPlugin.prototype.apply = function(compiler) { | ||
var moduleAssets = {}; | ||
var moduleAsset = function (module, file) { | ||
if (module.userRequest) { | ||
moduleAssets[file] = path.join( | ||
path.dirname(file), | ||
path.basename(module.userRequest) | ||
); | ||
} | ||
}; | ||
// NOTE: make sure webpack is not writing multiple manifests simultaneously | ||
lock(function(release) { | ||
if (compiler.hooks) { | ||
compiler.hooks.afterEmit.tap('ManifestResourcePlugin', function(compilation) { | ||
release(); | ||
}); | ||
} else { | ||
compiler.plugin('after-emit', function(compilation, cb) { | ||
release(); | ||
cb(); | ||
}); | ||
compilation.applyPluginsAsync('webpack-manifest-resource-plugin-after-emit', manifest, compileCallback); | ||
} | ||
}); | ||
}.bind(this); | ||
if (compiler.hooks) { | ||
compiler.hooks.compilation.tap('ManifestResourcePlugin', function (compilation) { | ||
compiler.hooks.compilation.tap('ManifestResourcePlugin', compilation => { | ||
compilation.hooks.moduleAsset.tap('ManifestResourcePlugin', moduleAsset); | ||
}); | ||
compiler.hooks.emit.tap('ManifestResourcePlugin', emit); | ||
compiler.hooks.emit.tap('ManifestResourcePlugin', (compilation, compileCallback) => { | ||
this.emit(moduleAsset, compilation, compileCallback); | ||
}); | ||
} else { | ||
compiler.plugin('compilation', function (compilation) { | ||
compiler.plugin('compilation', compilation => { | ||
compilation.plugin('module-asset', moduleAsset); | ||
}); | ||
compiler.plugin('emit', emit); | ||
compiler.plugin('emit', (compilation, compileCallback) => { | ||
this.emit(moduleAsset, compilation, compileCallback); | ||
}); | ||
} | ||
@@ -334,0 +323,0 @@ }; |
{ | ||
"name": "webpack-manifest-resource-plugin", | ||
"version": "4.2.4", | ||
"version": "4.2.5", | ||
"description": "webpack manifest resource dependencies plugin", | ||
@@ -12,4 +12,3 @@ "keywords": [ | ||
"fs-extra": "^0.30.0", | ||
"lodash": ">=3.5 <5", | ||
"mutexify": "1.0.1" | ||
"lodash": ">=3.5 <5" | ||
}, | ||
@@ -16,0 +15,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
14275
291
- Removedmutexify@1.0.1
- Removedmutexify@1.0.1(transitive)