Skip to content

Commit a4a0d60

Browse files
author
Christopher Willis-Ford
committed
Remove resolve: { symlinks: false }, fix fallout
Turning off symlink resolution in webpack was a quick fix but complicates things by making webpack act less like Node.js than it otherwise would. This change restores default symlink resolution behavior for webpack, which matches Node. In order to make Babel work with `npm link`ed modules even when symlink resolution is enabled, the include paths for `babel-loader` are now being run through `fs.realpathSync`.
1 parent 4f095b7 commit a4a0d60

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

webpack.config.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
var CopyWebpackPlugin = require('copy-webpack-plugin');
22
var defaultsDeep = require('lodash.defaultsdeep');
3+
var fs = require('fs');
34
var path = require('path');
45
var webpack = require('webpack');
56

7+
/**
8+
* Resolve a babel plugin or preset to a real path, resolving symlinks the way that Node.js would.
9+
* Helps work around the differences between webpack's module lookup and Node's when `npm link` is in use.
10+
* @param {string} prefix - 'babel-plugin' for a plugin, 'babel-preset' for a preset, etc.
11+
* @param {string|Array} item - either a plugin/preset name or path or an array with such a string at index 0.
12+
* @returns {string|Array} - the same type as `item` but the name/path will be replaced with an absolute path.
13+
*/
14+
const babelRealPath = function (prefix, item) {
15+
if (typeof item === 'string') {
16+
if (item.indexOf(prefix) !== 0) {
17+
item = [prefix, item].join('-');
18+
}
19+
return fs.realpathSync(require.resolve(item));
20+
}
21+
item[0] = babelRealPath(prefix, item[0]);
22+
return item;
23+
};
24+
625
var base = {
726
devServer: {
827
contentBase: false,
@@ -18,11 +37,13 @@ var base = {
1837
path.resolve(__dirname, 'node_modules', 'scratch-render', 'src'),
1938
path.resolve(__dirname, 'node_modules', 'scratch-storage', 'src'),
2039
path.resolve(__dirname, 'src')
21-
],
40+
].map(x => fs.realpathSync(x)),
2241
test: /\.js$/,
2342
loader: 'babel-loader',
2443
options: {
25-
presets: ['es2015']
44+
presets: [
45+
'es2015'
46+
].map(x => babelRealPath('babel-preset', x))
2647
}
2748
}
2849
]
@@ -32,10 +53,7 @@ var base = {
3253
include: /\.min\.js$/,
3354
minimize: true
3455
})
35-
],
36-
resolve: {
37-
symlinks: false
38-
}
56+
]
3957
};
4058

4159
module.exports = [
@@ -102,15 +120,15 @@ module.exports = [
102120
loader: 'expose-loader?Blockly'
103121
},
104122
{
105-
test: path.resolve(__dirname, 'node_modules', 'scratch-audio', 'src', 'index.js'),
123+
test: require.resolve('scratch-audio'),
106124
loader: 'expose-loader?AudioEngine'
107125
},
108126
{
109-
test: path.resolve(__dirname, 'node_modules', 'scratch-render', 'src', 'index.js'),
127+
test: require.resolve('scratch-render'),
110128
loader: 'expose-loader?RenderWebGL'
111129
},
112130
{
113-
test: path.resolve(__dirname, 'node_modules', 'scratch-storage', 'src', 'index.js'),
131+
test: require.resolve('scratch-storage'),
114132
loader: 'expose-loader?Scratch.Storage'
115133
}
116134
])

0 commit comments

Comments
 (0)