Skip to content

Commit a90e56a

Browse files
authored
Merge pull request element-hq#11994 from vector-im/dbkr/steal-daves-webpack_rel
Fix webpack config (by stealing Dave's config)
2 parents 024297c + d4e4610 commit a90e56a

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎webpack.config.js‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ module.exports = (env, argv) => {
2121
development['devtool'] = 'eval-source-map';
2222
}
2323

24+
// Resolve the directories for the react-sdk and js-sdk for later use. We resolve these early so we
25+
// don't have to call them over and over. We also resolve to the package.json instead of the src
26+
// directory so we don't have to rely on a index.js or similar file existing.
27+
const reactSdkSrcDir = path.resolve(require.resolve("matrix-react-sdk/package.json"), '..', 'src');
28+
const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src');
29+
2430
return {
2531
...development,
2632

@@ -110,21 +116,21 @@ module.exports = (env, argv) => {
110116
{
111117
test: /\.(ts|js)x?$/,
112118
include: (f) => {
119+
// our own source needs babel-ing
120+
if (f.startsWith(path.resolve(__dirname, 'src'))) return true;
121+
113122
// we use the original source files of react-sdk and js-sdk, so we need to
114-
// run them through babel.
115-
if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-js-sdk'))) return true;
116-
if (f.startsWith(path.resolve(__dirname, 'node_modules', 'matrix-react-sdk'))) return true;
123+
// run them through babel. Because the path tested is the resolved, absolute
124+
// path, these could be anywhere thanks to yarn link. We must also not
125+
// include node modules inside these modules, so we add 'src'.
126+
if (f.startsWith(reactSdkSrcDir)) return true;
127+
if (f.startsWith(jsSdkSrcDir)) return true;
128+
117129
// but we can't run all of our dependencies through babel (many of them still
118130
// use module.exports which breaks if babel injects an 'include' for its
119131
// polyfills: probably fixable but babeling all our dependencies is probably
120-
// not necessary anyway).
121-
if (f.startsWith(path.resolve(__dirname, 'node_modules'))) return false;
122-
// anything else gets babeled (our own source files, and also modules that
123-
// are yarn linked from somewhere else because this tests the absolute,
124-
// resolved path, so react-sdk and js-sdk fall under this case in a standard
125-
// dev setup. This will presumably start running any other module through
126-
// babel if yarn linked... caveat emptor.
127-
return true;
132+
// not necessary anyway). So, for anything else, don't babel.
133+
return false;
128134
},
129135
loader: 'babel-loader',
130136
options: {

0 commit comments

Comments
 (0)