Skip to content
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

Webpack support + remove legacy compat libraries #321

Merged
merged 13 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from 9 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
88 changes: 37 additions & 51 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = function (grunt) {

grunt.loadNpmTasks('grunt-curl');
grunt.loadNpmTasks('grunt-zip');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-closure-compiler');
grunt.loadNpmTasks('grunt-bump');
Expand Down Expand Up @@ -66,19 +65,6 @@ module.exports = function (grunt) {
}
};

gruntConfig.copy = {
'compat-pubnub-md': {
src: '<%= dirs.compat %>/pubnub.md',
dest: '<%= dirs.dest %>/compat-pubnub.md',
flatten: true
},
'compat-pusher-md': {
src: '<%= dirs.compat %>/pusher.md',
dest: '<%= dirs.dest %>/compat-pusher.md',
flatten: true
}
};

gruntConfig.concat = {
ably: {
dest: '<%= dirs.dest %>/ably.js',
Expand All @@ -88,21 +74,19 @@ module.exports = function (grunt) {
dest: '<%= dirs.dest %>/ably.noencryption.js',
nonull: true
},
pubnub: {
dest: '<%= dirs.dest %>/compat-pubnub.js',
'ably-commonjs': {
dest: '<%= dirs.dest %>/ably-commonjs.js',
nonull: true
},
pusher: {
dest: '<%= dirs.dest %>/compat-pusher.js',
'ably-commonjs.noencryption': {
dest: '<%= dirs.dest %>/ably-commonjs.noencryption.js',
nonull: true
}
};

gruntConfig['closure-compiler'] = {
'ably.js': compilerSpec('<%= dirs.static %>/ably.js'),
'ably.noencryption.js': compilerSpec('<%= dirs.static %>/ably.noencryption.js'),
'pubnub.js': compilerSpec('<%= dirs.static %>/compat-pubnub.js'),
'pusher.js': compilerSpec('<%= dirs.static %>/compat-pusher.js')
'ably.noencryption.js': compilerSpec('<%= dirs.static %>/ably.noencryption.js')
};

var ablyFiles = [
Expand Down Expand Up @@ -169,6 +153,23 @@ module.exports = function (grunt) {
'<%= dirs.fragments %>/ably-epilogue.js'
);

gruntConfig.concat['ably-commonjs'].src = [].concat(
'<%= dirs.fragments %>/license.js',
'<%= dirs.fragments %>/ably-commonjs-prologue.js',
'<%= dirs.crypto_js %>/core.js',
'<%= dirs.crypto_js %>/sha256.js',
'<%= dirs.crypto_js %>/hmac.js',
'<%= dirs.crypto_js %>/enc-base64.js',
'<%= dirs.crypto_js %>/cipher-core.js',
'<%= dirs.crypto_js %>/aes.js',
'<%= dirs.crypto_js %>/lib-typedarrays.js',

'<%= dirs.browser %>/lib/util/crypto.js',
ablyFiles,

'<%= dirs.fragments %>/ably-commonjs-epilogue.js'
);

gruntConfig.concat['ably.noencryption'].src = [].concat(
'<%= dirs.fragments %>/license.js',
'<%= dirs.fragments %>/ably-prologue.js',
Expand All @@ -182,19 +183,18 @@ module.exports = function (grunt) {
'<%= dirs.fragments %>/ably-epilogue.js'
);

gruntConfig.concat['pubnub'].src = [
gruntConfig.concat['ably-commonjs.noencryption'].src = [].concat(
'<%= dirs.fragments %>/license.js',
'<%= dirs.browser %>/compat/pubnub.js'
];
'<%= dirs.fragments %>/ably-commonjs-prologue.js',
'<%= dirs.crypto_js %>/core.js',
'<%= dirs.crypto_js %>/sha256.js',
'<%= dirs.crypto_js %>/hmac.js',
'<%= dirs.crypto_js %>/enc-base64.js',

gruntConfig.concat['pusher'].src = [
'<%= dirs.fragments %>/license.js',
'<%= dirs.fragments %>/prologue.js',
'<%= dirs.common %>/lib/util/eventemitter.js',
'<%= dirs.common %>/lib/util/utils.js',
'<%= dirs.browser %>/compat/pusher.js',
'<%= dirs.fragments %>/epilogue.js'
];
ablyFiles,

'<%= dirs.fragments %>/ably-commonjs-epilogue.js'
);

gruntConfig.bump = {
options: {
Expand All @@ -220,9 +220,7 @@ module.exports = function (grunt) {
grunt.registerTask('build', [
'set-library-version',
'ably.js',
'ably.noencryption.js',
'pusher',
'pubnub'
'ably.noencryption.js'
]);

grunt.registerTask('ably.js', [
Expand All @@ -233,21 +231,9 @@ module.exports = function (grunt) {
'concat:ably.noencryption'
]);

grunt.registerTask('pusher', [
'concat:pusher',
'copy:compat-pusher-md'
]);

grunt.registerTask('pubnub', [
'concat:pubnub',
'copy:compat-pubnub-md'
]);

grunt.registerTask('minify', [
'closure-compiler:ably.js',
'closure-compiler:ably.noencryption.js',
'closure-compiler:pubnub.js',
'closure-compiler:pusher.js'
'closure-compiler:ably.noencryption.js'
]);

grunt.registerTask('all', ['build', 'minify', 'requirejs']);
Expand Down Expand Up @@ -284,17 +270,17 @@ module.exports = function (grunt) {

grunt.registerTask('test:karma:run',
'Concat files and then run the Karma test runner. Assumes a Karma server is running',
['copy', 'concat', 'requirejs', 'karma:run']
['concat', 'requirejs', 'karma:run']
);

grunt.registerTask('test:nodeunit',
'Concat files and then run the Nodeunit specs\nOptions\n --test [tests] e.g. --test test/rest/auth.js',
['copy', 'concat', 'requirejs', 'nodeunit']
['concat', 'requirejs', 'nodeunit']
);

grunt.registerTask('test:webserver',
'Launch the Nodeunit test web server on http://localhost:3000/',
['copy', 'concat', 'requirejs', 'nodeunit:webserver']
['concat', 'requirejs', 'nodeunit:webserver']
);

grunt.registerTask('release:refresh-pkgVersion',
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ For the rest-only library:
var rest = Ably.Rest;
```

### Using WebPack

WebPack will search your `node_modules` folder by default, so if you include `ably` in your `package.json` file, when running Webpack the following will allow you to `require` Ably. Alternatively, you can reference the `ably-commonjs.js` static file directly if not in your `node_modules` folder.

```javascript
var Ably = require('ably/browser/static/ably-commonjs.js');
var realtime = new Ably.Realtime(options);
```

If you are using ES6 and or a transpiler that suppots ES6 modules with WebPack, you can include Ably as follows:

```javascript
import Ably from 'ably/browser/static/ably-commonjs.js'
let realtime = new Ably.Realtime(options)
```

## Using the Realtime API

### Introduction
Expand Down
Loading