Repository URL to install this package:
|
Version:
3.8.1 ▾
|
/**
* @file @todo where is config.get for alias?
*/
import { isObj } from 'exotic'
// import { OverridePlugin } from '@skava/composer'
import { resolveToRoot } from '../resolveToRoot'
import { alias } from '../aliasing'
import { Configuration, Options } from '../typings'
// These extensions are tried when resolving a file.
// const EXT = ['.js', '.jsx', '.json', '.scss', '.css']
const EXT = ['.js', '.jsx', '.json', '.ts', '.tsx', '.graphql']
/**
* @todo https://www.npmjs.com/package/directory-named-webpack-plugin
* @see https://webpack.js.org/configuration/resolve/#resolve-mainfiles can use for theming
* @see https://github.com/lerna/lerna/issues/1049#issuecomment-335014011
*/
export default function resolveModules(
config: Configuration,
options: Options
) {
const existingResolve = config.resolve
// const plugin = new OverridePlugin().plugin
// config.plugins.push(plugin)
/**
* https://webpack.js.org/guides/build-performance/#resolving
*/
config.resolve = {
extensions: EXT,
// @todo @@configurable-env ['esnext',
mainFields: ['main'],
alias,
}
if (isObj(existingResolve) === true) {
Object.assign(config.resolve)
}
/**
* This allows you to set a fallback for where Webpack should look for modules.
* We placed these paths second because we want `node_modules` to "win"
* if there are any conflicts. This matches Node resolution mechanism.
* https://github.com/facebookincubator/create-react-app/issues/253
*/
if (!process.env.PNP) {
config.resolve.modules = [].concat([
// resolveToRoot('./modules'),
// resolveToRoot('./packages'),
'./node_modules',
// 'modules',
// 'node_modules',
// 'scripts',
// 'config',
])
console.log('use PNP=true to use pnp')
return
}
if (process.env.PNP) {
const PnpWebpackPlugin = require('./PnpWebpackPlugin')
const plugins = [PnpWebpackPlugin]
config.resolve.plugins = plugins
config.resolveLoader = {
plugins,
}
}
}