1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Make Olm work with browserified js-sdk

We want to avoid distributing olm as part of the js-sdk, so we exclude it from
the browserified build. Previously this meant that you couldn't use olm this
way.

We can do better though: if the web page includes olm.js via a separate script
tag, that will set global.Olm, which we can get browserify to shim in.
This commit is contained in:
Richard van der Hoff
2017-01-27 17:15:35 +00:00
parent e71e32122c
commit c6e21c9c5c
2 changed files with 14 additions and 2 deletions

View File

@@ -9,9 +9,9 @@
"check": "npm run buildtest && jasmine-node specbuild --verbose --junitreport --captureExceptions", "check": "npm run buildtest && jasmine-node specbuild --verbose --junitreport --captureExceptions",
"gendoc": "jsdoc -r lib -P package.json -R README.md -d .jsdoc", "gendoc": "jsdoc -r lib -P package.json -R README.md -d .jsdoc",
"start": "babel -s -w -d lib src", "start": "babel -s -w -d lib src",
"build": "babel -s -d lib src && rimraf dist && mkdir dist && browserify --exclude olm browser-index.js -o dist/browser-matrix.js --ignore-missing && uglifyjs -c -m -o dist/browser-matrix.min.js dist/browser-matrix.js", "build": "babel -s -d lib src && rimraf dist && mkdir dist && browserify browser-index.js -o dist/browser-matrix.js && uglifyjs -c -m -o dist/browser-matrix.min.js dist/browser-matrix.js",
"dist": "npm run build", "dist": "npm run build",
"watch": "watchify --exclude olm browser-index.js -o dist/browser-matrix-dev.js -v", "watch": "watchify browser-index.js -o dist/browser-matrix-dev.js -v",
"lint": "eslint --max-warnings 121 src spec", "lint": "eslint --max-warnings 121 src spec",
"prepublish": "npm run build && git rev-parse HEAD > git-revision.txt" "prepublish": "npm run build && git rev-parse HEAD > git-revision.txt"
}, },
@@ -55,6 +55,7 @@
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.18.0", "babel-preset-es2015": "^6.18.0",
"browserify": "^10.2.3", "browserify": "^10.2.3",
"browserify-shim": "^3.8.13",
"eslint": "^3.13.1", "eslint": "^3.13.1",
"eslint-config-google": "^0.7.1", "eslint-config-google": "^0.7.1",
"istanbul": "^0.3.13", "istanbul": "^0.3.13",
@@ -66,5 +67,11 @@
}, },
"optionalDependencies": { "optionalDependencies": {
"olm": "https://matrix.org/packages/npm/olm/olm-2.2.1.tgz" "olm": "https://matrix.org/packages/npm/olm/olm-2.2.1.tgz"
},
"browserify": {
"transform": "browserify-shim"
},
"browserify-shim": {
"olm": "global:Olm"
} }
} }

View File

@@ -21,6 +21,11 @@ limitations under the License.
* @module crypto/OlmDevice * @module crypto/OlmDevice
*/ */
const Olm = require("olm"); const Olm = require("olm");
if (!Olm) {
// this happens if we were loaded via browserify and the Olm module was not
// loaded.
throw new Error("Olm is not defined");
}
const utils = require("../utils"); const utils = require("../utils");