unminified-webpack-plugin
Advanced tools
Comparing version 2.0.0 to 3.0.0
85
index.js
const webpack = require('webpack'); | ||
const path = require('path'); | ||
const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers'); | ||
const legacy = require('./legacy'); | ||
const support5 = require('./support5'); | ||
try { | ||
const majorVersion = +webpack.version.match(/^[0-9]+/)[0]; | ||
const getFileName = function(name, ext, opts) { | ||
if (name.match(/([-_.]min)[-_.]/)) { | ||
return name.replace(/[-_.]min/, ''); | ||
} | ||
const suffix = (opts.postfix || 'nomin') + '.' + ext; | ||
if (name.match(new RegExp('\.' + ext + '$'))) { | ||
return name.replace(new RegExp(ext + '$'), suffix) | ||
} | ||
return name + suffix; | ||
}; | ||
const UnminifiedWebpackPlugin = function(opts) { | ||
this.options = opts || {}; | ||
}; | ||
UnminifiedWebpackPlugin.prototype.apply = function(compiler) { | ||
const options = this.options; | ||
options.test = options.test || /\.(js|css)($|\?)/i; | ||
const containUgly = compiler.options.plugins.filter(function(plugin) { | ||
return plugin.constructor.name === 'UglifyJsPlugin'; | ||
}); | ||
if (!containUgly.length && compiler.options.mode === 'development') { | ||
return console.log('Ignore generating unminified version, since no UglifyJsPlugin provided, or running in development mode'); | ||
} | ||
compiler.hooks.compilation.tap('UnminifiedWebpackPlugin', function(compilation) { | ||
compilation.hooks.additionalAssets.tap('UnminifiedWebpackPlugin', function() { | ||
const files = []; | ||
compilation.chunks.forEach(function(chunk) { | ||
chunk.files.forEach(function(file) { | ||
files.push(file); | ||
}); | ||
}); | ||
compilation.additionalChunkAssets.forEach(function(file) { | ||
files.push(file); | ||
}); | ||
const finalFiles = files.filter(ModuleFilenameHelpers.matchObject.bind(null, options)); | ||
const bannerPlugin = compiler.options.plugins.find(function(plugin) { | ||
return plugin.constructor.name === 'BannerPlugin'; | ||
}); | ||
finalFiles.forEach(function(file) { | ||
const asset = compilation.assets[file]; | ||
let matchedBanners = []; | ||
if (bannerPlugin) { | ||
matchedBanners = [file].filter(ModuleFilenameHelpers.matchObject.bind(null, bannerPlugin.options)); | ||
} | ||
const source = matchedBanners.length ? bannerPlugin.banner + asset.source() : asset.source(); | ||
compilation.assets[getFileName(file, path.extname(file).substr(1), options)] = { | ||
source: function() { | ||
return source; | ||
}, | ||
size: function() { | ||
return source.length; | ||
} | ||
}; | ||
}); | ||
}); | ||
}); | ||
}; | ||
module.exports = UnminifiedWebpackPlugin; | ||
if (majorVersion >=5) { | ||
module.exports = support5; | ||
} | ||
else { | ||
module.exports = legacy; | ||
} | ||
} catch (error) { | ||
console.error(`unknown webpack version: [${webpack.version}]`); | ||
} |
{ | ||
"name": "unminified-webpack-plugin", | ||
"version": "2.0.0", | ||
"description": "A `webpack` plugin for generating un-minified JavaScript files along with UglifyJsPlugin.", | ||
"version": "3.0.0", | ||
"description": "A `webpack` plugin for generating un-minified JavaScript files along with minimize.", | ||
"main": "index.js", | ||
@@ -10,6 +10,8 @@ "scripts": { | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"legacy.js", | ||
"support5.js" | ||
], | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=10.0.0" | ||
}, | ||
@@ -31,9 +33,9 @@ "repository": { | ||
"devDependencies": { | ||
"del": "^3.0.0", | ||
"mocha": "^5.0.2", | ||
"webpack": "^4.0.0" | ||
"del": "^6.0.0", | ||
"mocha": "^8.3.2", | ||
"webpack": "^5.36.2" | ||
}, | ||
"peerDependencies": { | ||
"webpack": "^4.0.0" | ||
"webpack": "^5.36.2" | ||
} | ||
} |
@@ -10,5 +10,7 @@ unminified-webpack-plugin | ||
> `webpack@4` and `webpack@5` is now supported. | ||
A `webpack` plugin for generating un-minified JavaScript files along with UglifyJsPlugin. | ||
A `webpack` plugin for generating un-minified JavaScript files along with `minimize`. | ||
>This plugin should only be used while you are developing standalone library | ||
@@ -33,7 +35,8 @@ | ||
```javascript | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
var UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); | ||
module.exports = { | ||
mode: 'production', | ||
entry: { | ||
@@ -61,5 +64,5 @@ index: './src/index.js' | ||
```javascript | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
var UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin'); | ||
@@ -76,3 +79,3 @@ module.exports = { | ||
new UnminifiedWebpackPlugin({ | ||
postfix: 'unmin'//specify "nomin" postfix, | ||
postfix: 'unmin',//specify "nomin" postfix | ||
include: /polyfill.*/, | ||
@@ -98,5 +101,5 @@ exclude: /test.*/ | ||
[npm-image]: https://badge.fury.io/js/unminified-webpack-plugin.png | ||
[travis-url]:https://api.travis-ci.org/leftstick/unminified-webpack-plugin.svg?branch=master | ||
[travis-url]: https://travis-ci.com/leftstick/unminified-webpack-plugin.svg?branch=master | ||
[david-url]: https://david-dm.org/leftstick/unminified-webpack-plugin.png | ||
[dt-url]:https://img.shields.io/npm/dt/unminified-webpack-plugin.svg | ||
[license-url]:https://img.shields.io/npm/l/unminified-webpack-plugin.svg |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
11972
6
181
101
1
1