Skip to content

Commit

Permalink
feat(docz-core): use NODE_PATH to resolve modules (#516)
Browse files Browse the repository at this point in the history
use resolve.modules to add NODE_PATH
  • Loading branch information
yaodingyd authored and pedronauck committed Dec 17, 2018
1 parent 5dc1725 commit cc86f93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/docz-core/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ const populateNodePath = () => {
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
// We also resolve them to make sure all tools using them work consistently.
return (envDotProp.get('node.path') || '')
.split(path.delimiter)
.filter((folder: any) => folder && !path.isAbsolute(folder))
.map((folder: any) => path.resolve(root, folder))
.join(path.delimiter)
envDotProp.set(
'node.path',
envDotProp
.get('node.path', '')
.split(path.delimiter)
.filter((folder: any) => folder && !path.isAbsolute(folder))
.map((folder: any) => path.resolve(root, folder))
.join(path.delimiter)
)
}

const configDotEnv = () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/docz-core/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import friendlyErrors from 'friendly-errors-webpack-plugin'
import manifestPlugin from 'webpack-manifest-plugin'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import * as TerserPlugin from 'terser-webpack-plugin'
import envDotProp from 'env-dot-prop'

import * as loaders from './loaders'
import * as paths from '../config/paths'
Expand Down Expand Up @@ -161,6 +162,13 @@ export const createConfig = (args: Args, env: Env) => async (
.add('node_modules')
.add(srcPath)
.add(paths.root)
.merge([
envDotProp
.get('node.path')
.split(path.delimiter)
.filter(Boolean),
])


config.resolveLoader
.set('symlinks', true)
Expand Down

0 comments on commit cc86f93

Please sign in to comment.