Skip to content

Commit

Permalink
fix issue #2, #3
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed Jun 24, 2016
1 parent a378a61 commit 7672035
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
'use strict';

var webpack = require('webpack');
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var resolve = path.resolve;
var ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');


var getFileName = function(name) {
var getFileName = function(name, opts) {
var minIndex = name.indexOf('min');
if (minIndex > -1) {
return name.substring(0, minIndex - 1) + name.substring(minIndex + 3);
}
var nonmin = opts.postfix || 'nomin';
var jsIndex = name.indexOf('js');
if (jsIndex > -1) {
return name.substring(0, jsIndex - 1) + '.nomin.js';
return name.substring(0, jsIndex - 1) + '.' + nonmin + '.js';
}
return name + 'nomin.js';
return name + nonmin + '.js';
};

var UnminifiedWebpackPlugin = function(opts) {
Expand Down Expand Up @@ -50,7 +47,7 @@ UnminifiedWebpackPlugin.prototype.apply = function(compiler) {
files = files.filter(ModuleFilenameHelpers.matchObject.bind(null, options));
files.forEach(function(file) {
var asset = compilation.assets[file];
compilation.assets[getFileName(file)] = {
compilation.assets[getFileName(file, options)] = {
source: function() {
return asset.source();
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unminified-webpack-plugin",
"version": "1.0.1",
"version": "1.1.0",
"description": "A `webpack` plugin for generating un-minified JavaScript files along with UglifyJsPlugin.",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/leftstick/NoMinifiedEmiterPlugin#readme",
"devDependencies": {
"del": "^2.2.0",
"del": "^2.2.1",
"mocha": "^2.5.3",
"webpack": "^1.13.1"
}
Expand Down
26 changes: 26 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,30 @@ describe('testing', function() {
});
});

it('generating while nonmin options specified', function(done) {
var compiler = webpack({
entry: {
index: resolve(curDir, 'simple', 'index.js')
},
output: {
path: resolve(curDir, 'build'),
filename: 'bundle.js'
},
plugins: [
new webpack.BannerPlugin('The fucking shit'),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new UnminifiedWebpackPlugin({postfix: 'nnnmin'})
]
});

compiler.run(function(err, stats) {
assert(fileExist(resolve(curDir, 'build', 'bundle.nnnmin.js')));
done();
});
});

});

0 comments on commit 7672035

Please sign in to comment.