/
intercept.js
52 lines (47 loc) · 1.97 KB
/
intercept.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const VeniaUiResolverPlugin = require('./lib/VeniaUiResolverPlugin');
const path = require('path');
const {cachedCleverMerge} = require('webpack/lib/util/cleverMerge');
const packagesToOverride = process.env.FOOMAN_OVERRIDEPACKAGES
? process.env.FOOMAN_OVERRIDEPACKAGES.split(',')
: ['@magento/venia-ui/lib' , '@magento/peregrine/lib'];
let resolverPlugins = [];
packagesToOverride.forEach(function(package) {
const parts = package.split('/');
const namespace = parts[0];
const packagename = parts[1];
const mainFolder = parts[2];
const pluginName = 'fooman/' + packagename + '-override-resolver';
const destinationDir = path.resolve(__dirname, '..', '..', '..', 'src', 'overrides', packagename);
const sourceDir = path.resolve(__dirname, '..', '..', '..', 'node_modules', namespace, packagename, mainFolder);
const myResolverPlugin = new VeniaUiResolverPlugin({
name: pluginName,
projectPath: destinationDir,
veniaUiModulePath: sourceDir
});
resolverPlugins.push(myResolverPlugin);
});
module.exports = targets => {
const webpackCompiler = targets.of('@magento/pwa-buildpack').webpackCompiler;
webpackCompiler.tap(compiler =>
compiler.resolverFactory.hooks.resolveOptions
.for('normal')
.tap('AddVeniaResolverToWebpackConfig', resolveOptions => {
const plugin = Object.assign(
{
plugins: resolverPlugins
});
return cachedCleverMerge(plugin, resolveOptions);
})
);
webpackCompiler.tap(compiler =>
compiler.resolverFactory.hooks.resolveOptions
.for('context')
.tap('AddVeniaResolverToWebpackConfig', resolveOptions => {
const plugin = Object.assign(
{
plugins: resolverPlugins
});
return cachedCleverMerge(plugin, resolveOptions);
})
);
};