Repository URL to install this package:
|
Version:
1.1.15 ▾
|
import { delimiter } from 'path'
import { isObj } from 'uxui-modules/exotic'
import { OverridePlugin } from '@skava/composer'
// ~/config/resolveToRoot
import { resolveToRoot } from '../../config/resolveToRoot'
import { alias } from '../../config/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']
process.env.NODE_PATH = resolveToRoot('node_modules')
/**
* @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)
config.resolve = {
extensions: EXT,
alias,
/**
* 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
*/
// modules: ['node_modules', resolveToRoot('../packages')].concat(
// // It is guaranteed to exist because we tweak it in `env.js`
// process.env.NODE_PATH.split(delimiter).filter(Boolean)
// ),
modules: [
resolveToRoot('../packages'),
resolveToRoot('node_modules'),
'node_modules',
],
// @note changed with @monorepo
// https://webpack.js.org/guides/build-performance/#resolving
// symlinks: false,
// symlinks: true,
// cachePredicate: () => false,
// unsafeCache: true,
}
if (isObj(existingResolve) === true) {
Object.assign(config.resolve)
}
}