Skip to content

Commit 7821740

Browse files
committed
Include olm in the webpack if it's been installed
.. to make it easy to build a crypto-enabled vector
1 parent 819b80d commit 7821740

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

‎webpack.config.js‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var path = require('path');
22
var webpack = require('webpack');
33

4+
var olm_path = path.resolve('./node_modules/olm');
5+
46
module.exports = {
57
module: {
68
preLoaders: [
@@ -29,15 +31,36 @@ module.exports = {
2931
// alias any requires to the react module to the one in our path, otherwise
3032
// we tend to get the react source included twice when using npm link.
3133
react: path.resolve('./node_modules/react'),
34+
35+
// matrix-js-sdk will use olm if it is available,
36+
// but does not explicitly depend on it. Pull it
37+
// in from node_modules if it's there.
38+
olm: olm_path,
3239
},
3340
},
3441
plugins: [
35-
new webpack.IgnorePlugin(/^olm/),
3642
new webpack.DefinePlugin({
3743
'process.env': {
3844
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
3945
}
40-
})
46+
}),
47+
48+
// olm.js includes "require 'fs'", which is never
49+
// executed in the browser. Ignore it.
50+
new webpack.IgnorePlugin(/^fs$/, /node_modules\/olm$/)
4151
],
4252
devtool: 'source-map'
4353
};
54+
55+
// ignore olm.js if it's not installed.
56+
(function() {
57+
var fs = require('fs');
58+
try {
59+
fs.lstatSync(olm_path);
60+
console.log("Olm is installed; including it in bundle");
61+
} catch (e) {
62+
module.exports.plugins.push(
63+
new webpack.IgnorePlugin(/^olm$/)
64+
);
65+
}
66+
}) ();

0 commit comments

Comments
 (0)