webpack: Use `require` to look for olm

Since https://github.com/matrix-org/matrix-js-sdk/pull/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.
This commit is contained in:
Richard van der Hoff 2016-06-20 10:47:16 +01:00
parent 654429dbdb
commit 664f809362
1 changed files with 10 additions and 20 deletions

View File

@ -2,8 +2,6 @@ var path = require('path');
var webpack = require('webpack'); var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin"); var ExtractTextPlugin = require("extract-text-webpack-plugin");
var olm_path = path.resolve('./node_modules/olm');
module.exports = { module.exports = {
module: { module: {
preLoaders: [ preLoaders: [
@ -45,11 +43,6 @@ module.exports = {
// same goes for js-sdk // same goes for js-sdk
"matrix-js-sdk": path.resolve('./node_modules/matrix-js-sdk'), "matrix-js-sdk": path.resolve('./node_modules/matrix-js-sdk'),
// matrix-js-sdk will use olm if it is available,
// but does not explicitly depend on it. Pull it
// in from node_modules if it's there.
olm: olm_path,
}, },
}, },
plugins: [ plugins: [
@ -65,20 +58,17 @@ module.exports = {
// olm.js includes "require 'fs'", which is never // olm.js includes "require 'fs'", which is never
// executed in the browser. Ignore it. // executed in the browser. Ignore it.
new webpack.IgnorePlugin(/^fs$/, /node_modules\/olm$/) new webpack.IgnorePlugin(/^fs$/, /\/olm$/)
], ],
devtool: 'source-map' devtool: 'source-map'
}; };
// ignore olm.js if it's not installed. // ignore olm.js if it's not installed, to avoid a scary-looking error.
(function() { try {
var fs = require('fs'); require('olm');
try {
fs.lstatSync(olm_path);
console.log("Olm is installed; including it in webpack bundle"); console.log("Olm is installed; including it in webpack bundle");
} catch (e) { } catch (e) {
module.exports.plugins.push( module.exports.plugins.push(
new webpack.IgnorePlugin(/^olm$/) new webpack.IgnorePlugin(/^olm$/)
); );
} }
}) ();