1 | import * as ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin'
|
2 | import * as PnpWebpackPlugin from 'pnp-webpack-plugin'
|
3 | import * as path from 'path'
|
4 | import Berun from '@berun/berun'
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | class PnpWebpackPluginClass {
|
10 | apply(compiler) {
|
11 | return PnpWebpackPlugin.apply(compiler)
|
12 | }
|
13 | }
|
14 |
|
15 | class 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 | */
|
25 | export 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 |
|
56 |
|
57 | .use(PnpWebpackPluginClass)
|
58 | .end()
|
59 |
|
60 | berun.webpack.resolveLoader
|
61 | .plugin('pnp-resolve')
|
62 |
|
63 |
|
64 | .use(PnpWebpackPluginClassModuleLoader)
|
65 | }
|