Socket
Socket
Sign inDemoInstall

webpack-manifest-resource-plugin

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-manifest-resource-plugin - npm Package Compare versions

Comparing version 1.1.0-beta.1 to 2.0.0

6

History.md
2.0.0 / 2017-12-08
==================
* feat: webpack dll manifest merge project manifest
1.0.0 / 2017-11-09

@@ -3,0 +9,0 @@ ==================

111

lib/plugin.js
var path = require('path');
var fs = require('fs');
var fse = require('fs-extra');

@@ -15,2 +16,3 @@ var _ = require('lodash');

transformExtensions: /^(gz|map)$/i,
asset: true,
writeToFileEmit: false,

@@ -21,3 +23,3 @@ seed: null,

generate: null,
sort: null,
sort: null
}, opts || {});

@@ -59,2 +61,10 @@ }

ManifestPlugin.prototype.isMatch = (regexArray, strMatch, defaultMatch = false) => {
if (!regexArray || (Array.isArray(regexArray) && regexArray.length === 0)) {
return defaultMatch;
}
regexArray = Array.isArray(regexArray) ? regexArray : [regexArray];
return regexArray.some(item => new RegExp(item, '').test(strMatch));
};
ManifestPlugin.prototype.getDeps = function(manifest, commonsChunk) {

@@ -64,15 +74,43 @@ const commonScriptPaths = [];

const manifestDeps = {};
let commonsChunkItemIsString = true;
commonsChunk.forEach(item => {
const jsKey = `${item}.js`;
const cssKey = `${item}.css`;
manifest[jsKey] && commonScriptPaths.push(manifest[jsKey]);
manifest[cssKey] && commonCSSPaths.push(manifest[cssKey]);
commonsChunkItemIsString = typeof item === 'string';
if (commonsChunkItemIsString) {
const jsKey = `${item}.js`;
const cssKey = `${item}.css`;
manifest[jsKey] && commonScriptPaths.push(manifest[jsKey]);
manifest[cssKey] && commonCSSPaths.push(manifest[cssKey]);
}
});
Object.keys(manifest).forEach(item => {
if (/\.js$/.test(item) && !commonsChunk.includes(item.replace(/\.js$/, ''))) {
manifestDeps[item] = {
js: commonScriptPaths.concat(manifest[item]),
css: commonCSSPaths.concat(manifest[item.replace(/\.js$/, '.css')] || []),
};
Object.keys(manifest).forEach(pageKey => {
if (/\.js$/.test(pageKey)) {
const pageName = pageKey.replace(/\.js$/, '');
if (commonsChunkItemIsString) {
// 不处理公共 commonsChunk 依赖
if (!commonsChunk.includes(pageName)) {
manifestDeps[pageKey] = {
js: commonScriptPaths.concat(manifest[pageKey]),
css: commonCSSPaths.concat(manifest[pageKey.replace(/\.js$/, '.css')] || []),
};
}
} else {
const pageCommonScriptPaths = [];
const pageCommonCSSPaths = [];
const isCommonsChunk = commonsChunk.find(dll =>{
return dll.name === pageName;
});
commonsChunk.forEach(dll => {
if (!isCommonsChunk && this.isMatch(dll.include, pageName, true) && !this.isMatch(dll.exclude, pageName, false)) {
const jsKey = `${dll.name}.js`;
const cssKey = `${dll.name}.css`;
manifest[jsKey] && pageCommonScriptPaths.push(manifest[jsKey]);
manifest[cssKey] && pageCommonCSSPaths.push(manifest[cssKey]);
}
});
manifestDeps[pageKey] = {
js: pageCommonScriptPaths.concat(manifest[pageKey]),
css: pageCommonCSSPaths.concat(manifest[pageKey.replace(/\.js$/, '.css')] || []),
};
}
}

@@ -84,16 +122,26 @@ });

ManifestPlugin.prototype.getResource = function(manifest, publicPath) {
var buildPath = this.opts.buildPath.replace(this.opts.baseDir, '').replace(/^\//, '');
var fileNormalizeManifest = this.normalizeFile(manifest, publicPath);
var normalizeManifest = this.normalize(manifest);
var manifestDll = this.opts.manifestDll;
const buildPath = this.opts.buildPath.replace(this.opts.baseDir, '').replace(/^\//, '');
const normalizeManifest = this.normalize(manifest);
const manifestDll = this.opts.manifestDll;
if (manifestDll && typeof manifestDll === 'boolean') {
return normalizeManifest;
} else {
if (manifestDll && typeof manifestDll === 'object') {
Object.keys(manifestDll).forEach(key => {
normalizeManifest[key] = manifestDll[key];
const commonsChunk = this.opts.commonsChunk;
const dllConfig = this.opts.dllConfig;
if (dllConfig) { // 合并 dll manifest 到 manifest
const dllDir = this.opts.dllDir;
const dllArray = Array.isArray(dllConfig) ? dllConfig : [dllConfig];
dllArray.forEach(item => {
const dllManifestPath = path.join(dllDir, `config/manifest-${item.name}.json`);
if (fs.existsSync(dllManifestPath)) {
const dllManifestJSON = require(dllManifestPath);
Object.keys(dllManifestJSON).forEach(key => {
normalizeManifest[key] = dllManifestJSON[key];
});
commonsChunk.push(item);
}
});
}
var depsManifest = this.getDeps(normalizeManifest, this.opts.commonsChunk);
return Object.assign({}, fileNormalizeManifest, {
const depsManifest = this.getDeps(normalizeManifest, commonsChunk);
return Object.assign({}, normalizeManifest, {
deps: depsManifest,

@@ -229,15 +277,16 @@ info: { publicPath, buildPath }

var json = JSON.stringify(resource, null, 2);
var outputFolder = compilation.options.output.path;
var outputFile = path.resolve(compilation.options.output.path, this.opts.fileName);
var outputName = path.relative(outputFolder, outputFile);
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);
compilation.assets[outputName] = {
source: function() {
return json;
},
size: function() {
return json.length;
}
};
if (this.opts.assets) {
compilation.assets[outputName] = {
source: function() {
return json;
},
size: function() {
return json.length;
}
};
}

@@ -244,0 +293,0 @@ if (this.opts.writeToFileEmit) {

{
"name": "webpack-manifest-resource-plugin",
"version": "1.1.0-beta.1",
"version": "2.0.0",
"description": "manifest resource dependencies",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc