unminified-webpack-plugin
Advanced tools
Comparing version 1.2.0 to 1.3.0
58
index.js
@@ -1,8 +0,6 @@ | ||
'use strict'; | ||
const webpack = require('webpack'); | ||
const path = require('path'); | ||
const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers'); | ||
var webpack = require('webpack'); | ||
var ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers'); | ||
var getFileName = function(name, opts) { | ||
const getFileName = (name, ext, opts) => { | ||
if (name.match(/([-_.]min)[-_.]/)) { | ||
@@ -12,5 +10,5 @@ return name.replace(/[-_.]min/, ''); | ||
var suffix = (opts.postfix || 'nomin') + '.js'; | ||
if (name.match(/\.js$/)) { | ||
return name.replace(/js$/, suffix) | ||
const suffix = (opts.postfix || 'nomin') + '.' + ext; | ||
if (name.match(new RegExp('\.' + ext + '$'))) { | ||
return name.replace(new RegExp(ext), suffix) | ||
} | ||
@@ -21,3 +19,3 @@ | ||
var UnminifiedWebpackPlugin = function(opts) { | ||
const UnminifiedWebpackPlugin = function(opts) { | ||
this.options = opts || {}; | ||
@@ -27,8 +25,6 @@ }; | ||
UnminifiedWebpackPlugin.prototype.apply = function(compiler) { | ||
var options = this.options; | ||
options.test = options.test || /\.js($|\?)/i; | ||
const options = this.options; | ||
options.test = options.test || /\.(js|css)($|\?)/i; | ||
var containUgly = compiler.options.plugins.filter(function(plugin) { | ||
return plugin instanceof webpack.optimize.UglifyJsPlugin; | ||
}); | ||
const containUgly = compiler.options.plugins.filter(plugin => plugin.constructor.name === 'UglifyJsPlugin'); | ||
@@ -39,26 +35,26 @@ if (!containUgly.length) { | ||
compiler.plugin('compilation', function(compilation) { | ||
compilation.plugin('additional-chunk-assets', function(chunks, cb) { | ||
var files = []; | ||
chunks.forEach(function(chunk) { | ||
chunk.files.forEach(function(file) { | ||
compiler.plugin('compilation', (compilation) => { | ||
compilation.plugin('additional-assets', (cb) => { | ||
const files = []; | ||
compilation.chunks.forEach(chunk => { | ||
chunk.files.forEach(file => { | ||
files.push(file); | ||
}); | ||
}); | ||
compilation.additionalChunkAssets.forEach(function(file) { | ||
compilation.additionalChunkAssets.forEach(file => { | ||
files.push(file); | ||
}); | ||
files = files.filter(ModuleFilenameHelpers.matchObject.bind(null, options)); | ||
files.forEach(function(file) { | ||
var asset = compilation.assets[file]; | ||
compilation.assets[getFileName(file, options)] = { | ||
source: function() { | ||
return asset.source(); | ||
}, | ||
size: function() { | ||
return asset.source().length; | ||
} | ||
const finalFiles = files.filter(ModuleFilenameHelpers.matchObject.bind(null, options)); | ||
finalFiles.forEach(file => { | ||
const asset = compilation.assets[file]; | ||
const source = asset.source(); | ||
compilation.assets[getFileName(file, path.extname(file).substr(1), options)] = { | ||
source: () => source, | ||
size: () => source.length | ||
}; | ||
}); | ||
cb(); | ||
}); | ||
}); | ||
@@ -65,0 +61,0 @@ }; |
{ | ||
"name": "unminified-webpack-plugin", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A `webpack` plugin for generating un-minified JavaScript files along with UglifyJsPlugin.", | ||
@@ -12,2 +12,5 @@ "main": "index.js", | ||
], | ||
"engines" : { | ||
"node" : ">=8.0.0" | ||
}, | ||
"repository": { | ||
@@ -28,6 +31,6 @@ "type": "git", | ||
"devDependencies": { | ||
"del": "^2.2.2", | ||
"mocha": "^3.2.0", | ||
"webpack": "^1.14.0" | ||
"del": "^3.0.0", | ||
"mocha": "^4.0.1", | ||
"webpack": "^3.6.0" | ||
} | ||
} |
@@ -85,3 +85,5 @@ unminified-webpack-plugin | ||
new UnminifiedWebpackPlugin({ | ||
postfix: 'unmin'//specify "nomin" postfix | ||
postfix: 'unmin'//specify "nomin" postfix, | ||
include: /polyfill.*/, | ||
exclude: /test.*/ | ||
}) | ||
@@ -94,3 +96,6 @@ ] | ||
>`include`, `exclude` just work the same way as `UglifyJsPlugin` | ||
>Check [working-example](https://github.com/leftstick/unminified-webpack-plugin/blob/master/example/css-pack/README.md) for css assets support | ||
## LICENSE ## | ||
@@ -97,0 +102,0 @@ |
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
7620
110
48