Skip to content

Commit 664f809

Browse files
committed
webpack: Use require to look for olm
Since matrix-org/matrix-js-sdk#141, the jenkins build does pull in the olm module, but because it's using npm v2, buries it deep in node_modules. Rather than using the `fs` module to hunt for it, just try to `require` it in the webpack config.
1 parent 654429d commit 664f809

1 file changed

Lines changed: 10 additions & 20 deletions

File tree

webpack.config.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ var path = require('path');
22
var webpack = require('webpack');
33
var ExtractTextPlugin = require("extract-text-webpack-plugin");
44

5-
var olm_path = path.resolve('./node_modules/olm');
6-
75
module.exports = {
86
module: {
97
preLoaders: [
@@ -45,11 +43,6 @@ module.exports = {
4543

4644
// same goes for js-sdk
4745
"matrix-js-sdk": path.resolve('./node_modules/matrix-js-sdk'),
48-
49-
// matrix-js-sdk will use olm if it is available,
50-
// but does not explicitly depend on it. Pull it
51-
// in from node_modules if it's there.
52-
olm: olm_path,
5346
},
5447
},
5548
plugins: [
@@ -65,20 +58,17 @@ module.exports = {
6558

6659
// olm.js includes "require 'fs'", which is never
6760
// executed in the browser. Ignore it.
68-
new webpack.IgnorePlugin(/^fs$/, /node_modules\/olm$/)
61+
new webpack.IgnorePlugin(/^fs$/, /\/olm$/)
6962
],
7063
devtool: 'source-map'
7164
};
7265

73-
// ignore olm.js if it's not installed.
74-
(function() {
75-
var fs = require('fs');
76-
try {
77-
fs.lstatSync(olm_path);
78-
console.log("Olm is installed; including it in webpack bundle");
79-
} catch (e) {
80-
module.exports.plugins.push(
81-
new webpack.IgnorePlugin(/^olm$/)
82-
);
83-
}
84-
}) ();
66+
// ignore olm.js if it's not installed, to avoid a scary-looking error.
67+
try {
68+
require('olm');
69+
console.log("Olm is installed; including it in webpack bundle");
70+
} catch (e) {
71+
module.exports.plugins.push(
72+
new webpack.IgnorePlugin(/^olm$/)
73+
);
74+
}

0 commit comments

Comments
 (0)