Skip to content

Webpack UMD build available #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
server.*
published
*.log
dist
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Install
$ npm install json2csv --save
```

Include the module and run or [use it from the Command Line](https://github.com/zemirco/json2csv#command-line-interface).
Include the module and run or [use it from the Command Line](https://github.com/zemirco/json2csv#command-line-interface). It's also possible to include `json2csv` as a global using an HTML script tag, though it's normally recommended that modules are used.

```javascript
var json2csv = require('json2csv');
Expand Down Expand Up @@ -386,6 +386,23 @@ $ json2csv -i test.json -f name,version > test.csv
$ json2csv -i test.json -f name,version --no-header >> test.csv
```

## Include using a script tag (not recommended)

If it's not possible to work with node modules, `json2csv` can be declared as a global by requesting `dist/json2csv.js` via an HTML script tag:

```
<script src="node_modules/json2csv/dist/json2csv.js"></script>
<script>
console.log(typeof json2csv === 'function'); // true
</script>
```

### Building

When developing, it's necessary to run `webpack` to prepare the built script. This can be done easily with `npm run build`.

If `webpack` is not already available from the command line, use `npm install -g webpack`.

## Testing

Run the following command to test and return coverage
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"url": "https://github.com/zemirco/json2csv"
},
"scripts": {
"build": "webpack",
"prepublish": "npm run build",
"test": "eslint . && node test | tap-spec",
"test-coverage": "istanbul cover test/index.js --report lcovonly | tap-spec"
},
Expand All @@ -44,6 +46,7 @@
"eslint": "^2.12.0",
"istanbul": "^0.4.3",
"tap-spec": "^4.1.0",
"tape": "^4.0.0"
"tape": "^4.0.0",
"webpack": "^1.13.1"
}
}
16 changes: 16 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var webpack = require('webpack');

var webpackConfig = {
entry: './lib/json2csv.js',
resolve: {
extensions: ['', '.js']
},
output: {
path: __dirname + '/dist',
libraryTarget: 'umd',
library: 'json2csv',
filename: 'json2csv.js'
}
};

module.exports = webpackConfig;