webpack-node-externals
webpack-node-externals copied to clipboard
How to alias externaled module path?
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?
@liady
@ycjcl868 same question, looks like that you had avoided this by giving up external。
SSR bundle all not set alias in umi 3.2.0
There's a problem for me to do SSR building, it's our framework export alias module, and use
resolve.aliasto alias the module , like React, we useimport React from 'bar/lib/sdk/react'; // not use import React from 'react';so now, I only add
bar/lib/sdk/reactintowhiteList, 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...
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.