Skip to content
This repository has been archived by the owner on Jan 6, 2018. It is now read-only.

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajiv Tirumalareddy committed Jan 20, 2015
1 parent 076fdea commit f16f976
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
tests/fixtures/app/bundle.js
/artifacts/
npm-debug.log
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/artifacts/
/tests/
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Contributing Code to `webpack-strip`
-------------------------------

Please be sure to sign our [CLA][] before you submit pull requests or otherwise contribute to `webpack-strip`. This protects developers, who rely on [BSD license][].

[BSD license]: https://github.com/yahoo/webpack-strip/blob/master/LICENSE.md
[CLA]: https://yahoocla.herokuapp.com/
29 changes: 29 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Software License Agreement (BSD License)
========================================

Copyright (c) 2015, Yahoo! Inc. All rights reserved.
----------------------------------------------------

Redistribution and use of this software in source and binary forms, with or
without modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Yahoo! Inc. nor the names of YUI's contributors may be
used to endorse or promote products derived from this software without
specific prior written permission of Yahoo! Inc.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Webpack Strip
=============

Simple [Webpack](http://webpack.github.io/) loader to strip custom functions from your code. This can be useful if you want to use debug statements while developing your app but don't want this info exposed in your production code.

##Usage:

In your client js source files:

```javascript

var debug = require('debug')('MyFile');

var makeFoo = function () {
// The following two lines of code will be stripped with our webpack loader
debug('makeFoo called');
debug('makeFoo args', arguments);
// This code would remain
return 'Foo';
};

```

### Single function
In your webpack config:

```javascript
{
module: {
loaders: [
{ test: /\.js$/, loader: "webpack-strip?strip[]=debug" }
]
}
};
```

### Multiple functions
In your webpack config:

```javascript
{
module: {
loaders: [
{ test: /\.js$/, loader: "webpack-strip?strip[]=debug,strip[]=console.log" }
]
}
};
```

### Use as library
In your webpack config:

```javascript
var WebpackStrip = require('webpack-strip')
{
module: {
loaders: [
{ test: /\.js$/, loader: WebpackStrip.loader('debug', 'console.log') }
]
}
};
```
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

"use strict";

var loaderUtils = require('loader-utils');
Expand Down
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "webpack-strip",
"version": "0.0.1",
"description": "Webpack loader to strip arbitrary functions out of your code.",
"version": "0.1.0",
"description": "Webpack loader to strip arbitrary functions out of your production code.",
"main": "lib/index.js",
"scripts": {
"cover": "node node_modules/istanbul/lib/cli.js cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --reporter spec",
"lint": "./node_modules/.bin/jshint lib tests",
"test": "mocha tests/unit --recursive --reporter spec"
},
"keywords": [
Expand All @@ -13,10 +15,21 @@
"author": "Rajiv Tirumalareddy <[email protected]>",
"devDependencies": {
"chai": "^1.10.0",
"istanbul": "^0.3.5",
"jshint": "^2.5.11",
"mocha": "^2.1.0",
"webpack": "^1.4.15"
},
"dependencies": {
"loader-utils": "^0.2.6"
},
"licenses": [
{
"type": "BSD",
"url": "https://github.com/yahoo/webpack-strip/blob/master/LICENSE.md"
}
],
"jshintConfig": {
"node": true
}
}
9 changes: 7 additions & 2 deletions tests/fixtures/app/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

var makeFoo = function (bar, baz) {
// The following 2 lines of code will be stripped with our webpack loader
assert(1!==2, '1 must not equal 2');
debug('1 must not equal 2');
console.log('some debug info');
debug('better debug info');
// This code would remain
return new Foo(bar, baz);
};
23 changes: 14 additions & 9 deletions tests/unit/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

/*global describe,it */
'use strict';

Expand Down Expand Up @@ -28,37 +33,37 @@ var createWebpackConfigWithLoader = function (loaderOpt) {
var createWebpackTest = function (done) {
return function(err, stats) {

expect(err).to.be.null;
expect(stats.hasErrors()).to.be.false;
expect(err).to.be.null();
expect(stats.hasErrors()).to.be.false();

var statsJson = stats.toJson();
expect(statsJson.errors).to.have.length(0);

var originalSource = fs.readFileSync(cwd + '/index.js', {encoding: 'utf8'})
expect(originalSource).to.contain('assert');
var originalSource = fs.readFileSync(cwd + '/index.js', {encoding: 'utf8'});
expect(originalSource).to.contain('console.log');
expect(originalSource).to.contain('debug');

var strippedSource = statsJson.modules[0].source;
expect(strippedSource).to.not.contain('assert');
expect(strippedSource).to.not.contain('console.log');
expect(strippedSource).to.not.contain('debug');

done(err);
};
}
};


describe('integration', function () {
describe('webpack', function () {
it('should work with loader query params', function (done) {
webpack(
createWebpackConfigWithLoader(loaderLibPath + '?strip[]=assert,strip[]=debug'),
createWebpackConfigWithLoader(loaderLibPath + '?strip[]=console.log,strip[]=debug'),
createWebpackTest(done)
);
});

it('should work with loader usage as library', function (done) {
it('should work with loader used as library', function (done) {
webpack(
createWebpackConfigWithLoader(loaderLib.loader('assert', 'debug')),
createWebpackConfigWithLoader(loaderLib.loader('console.log', 'debug')),
createWebpackTest(done)
);
});
Expand Down

0 comments on commit f16f976

Please sign in to comment.