Skip to content

Commit

Permalink
better webpack support
Browse files Browse the repository at this point in the history
  • Loading branch information
briancappello committed Oct 6, 2016
1 parent 51adf0a commit 3e6f946
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ module.exports = function(grunt) {

clean: {
dist: 'dist',
build: 'build'
build: 'build',
version: 'src/version'
},

filegen: {
version: {
options: {
content: "'use strict';module.exports='<%= pkg.version %>';"
content: "'use strict';module.exports='<%= pkg.version %>';\n"
},
dest: '<%= clean.build %>/version.js'
dest: '<%= clean.version %>/index.js'
}
},

Expand Down Expand Up @@ -245,4 +246,4 @@ module.exports = function(grunt) {
grunt.registerTask('release:major', ['bump-only:major', 'default', 'bump-commit']);

grunt.registerTask('default', ['jsonlint', 'bower', 'clean', 'filegen:version', 'test', 'dist', 'minify', 'compress']);
};
};
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ Download the latest release [https://github.com/andredumas/techan.js/releases/la
npm install --save techan
```

#### Webpack (ES6)
```javascript
// webpack.config.js
config = {
...,
resolve: {
...,
alias: {
'techan': path.resolve('node_modules/techan/src/techan.js')
}
}
}

// usage
import * as d3 from 'd3';
import techan from 'techan';
```

### Bower Dependency

```
Expand Down Expand Up @@ -105,4 +123,4 @@ docker build -t andredumas/techan.js .
docker run --rm -it -p 8000:8000 andredumas/techan.js
```

As above, browse to [http://localhost:8000/examples/](http://localhost:8000/examples/) to see the examples.
As above, browse to [http://localhost:8000/examples/](http://localhost:8000/examples/) to see the examples.
13 changes: 9 additions & 4 deletions src/techan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
var _d3;

// If running in browser (window !undefined) and d3 available
if('undefined' != typeof window && window.d3) _d3 = window.d3;
else if('object' == typeof module) _d3 = require('d3'); // else we're in the only other supported mode: v8/node
else throw "Unsupported runtime environment: Could not find d3. Ensure defined globally on window, or available as dependency.";
if('undefined' != typeof window && (window.d3 || 'undefined' != typeof d3)) {
_d3 = window.d3 || d3;
}
// else we're in the only other supported mode: v8/node
else if('object' == typeof module) {
_d3 = require('d3');
}
else throw "Unsupported runtime environment: Could not find d3. Ensure defined globally (or on window), or available as dependency.";

module.exports = (function(d3) {
return {
version: require('../build/version'),
version: require('./version'),
accessor: require('./accessor')(),
indicator: require('./indicator')(d3),
plot: require('./plot')(d3),
Expand Down
1 change: 1 addition & 0 deletions src/version/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';module.exports='0.9.0-0';

0 comments on commit 3e6f946

Please sign in to comment.