Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to alias externaled module path? #66

Open
ycjcl868 opened this issue Jul 10, 2019 · 5 comments
Open

How to alias externaled module path? #66

ycjcl868 opened this issue Jul 10, 2019 · 5 comments

Comments

@ycjcl868
Copy link

ycjcl868 commented Jul 10, 2019

There's a problem for me to do SSR building, it's our framework export alias module, and use resolve.alias to alias the module , like React, we use

import React from 'bar/lib/sdk/react';

// not use
import React from 'react';

so now, I only add bar/lib/sdk/react into whiteList, but it's unconscionable to bundle all React library.

How could I solve the problem?

@ycjcl868
Copy link
Author

@liady

@Pines-Cheng
Copy link

@ycjcl868 same question, looks like that you had avoided this by giving up external。

@ycjcl868
Copy link
Author

SSR bundle all not set alias in umi 3.2.0

@ycjcl868 ycjcl868 mentioned this issue May 29, 2020
4 tasks
@liady
Copy link
Owner

liady commented Jul 12, 2020

There's a problem for me to do SSR building, it's our framework export alias module, and use resolve.alias to alias the module , like React, we use

import React from 'bar/lib/sdk/react';

// not use
import React from 'react';

so now, I only add bar/lib/sdk/react into whiteList, but it's unconscionable to bundle all React library.

How could I solve the problem?

@ycjcl868 just to make sure i understood - do you need to bundle bar/lib/sdk/react? Since this is what adding it to allowlist will do...

@liady liady reopened this Jul 12, 2020
@daniel-nagy
Copy link

I think they had a resolve alias for react but Webpack was requiring react as an external dependency instead of their aliased module. I just ran into a similar issue with lodash-es, which doesn't work in a node runtime. I tried to rewrite the import to lodash

resolve: {
  alias: {
    "lodash-es": "lodash"
  }
}

but Webpack was still requiring lodash-es. I was able to work around it with the following.

externals: [
  nodeExternals({ allowlist: ["lodash-es"] }),
  { "lodash-es": "commonjs lodash" }
]

Note that the resolve alias is not necessary in this case. This seems to be an issue with Webpack but it might be nice to add an API to this module to rewrite external modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants