UNPKG

1.79 kBPlain TextView Raw
1import * as ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin'
2import * as PnpWebpackPlugin from 'pnp-webpack-plugin'
3import * as path from 'path'
4import Berun from '@berun/berun'
5
6// Hack to use a class instead of an object
7// Prevents webpack-chain 'Cannot redefine property: __pluginArgs' error
8// Just use this class instead of PnpWebpackPlugin
9class PnpWebpackPluginClass {
10 apply(compiler) {
11 return PnpWebpackPlugin.apply(compiler)
12 }
13}
14
15class PnpWebpackPluginClassModuleLoader {
16 apply(compiler) {
17 return PnpWebpackPlugin.moduleLoader.apply(compiler, module)
18 }
19}
20
21/**
22 * Add resolve webpack configuration including
23 * module scope and pnp plugins
24 */
25export default (berun: Berun, _) => {
26 berun.webpack.resolve.modules
27 .add('node_modules')
28 .merge(process.env.NODE_PATH!.split(path.delimiter).filter(Boolean))
29 .end()
30 .extensions.merge([
31 '.ts',
32 '.tsx',
33 '.web.js',
34 '.mjs',
35 '.js',
36 '.json',
37 '.web.jsx',
38 '.jsx'
39 ])
40 .end()
41 .alias.set(
42 '@babel/runtime',
43 path.dirname(require.resolve('@babel/runtime/package.json'))
44 )
45 .end()
46 .alias.set('react-native', 'react-native-web')
47 .end()
48 .plugin('ModuleScope')
49 .use(ModuleScopePlugin, [
50 berun.options.paths.appSrc,
51 [berun.options.paths.appPackageJson]
52 ])
53 .end()
54 .plugin('pnp1')
55 // Adds support for installing with Plug'n'Play, leading to faster installs and adding
56 // guards against forgotten dependencies and such.
57 .use(PnpWebpackPluginClass)
58 .end()
59
60 berun.webpack.resolveLoader
61 .plugin('pnp-resolve')
62 // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
63 // from the current package.
64 .use(PnpWebpackPluginClassModuleLoader)
65}