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

context module doesn't work with array of aliases #11335

Closed
alexander-akait opened this issue Aug 17, 2020 · 8 comments · Fixed by #15332
Closed

context module doesn't work with array of aliases #11335

alexander-akait opened this issue Aug 17, 2020 · 8 comments · Fixed by #15332

Comments

@alexander-akait
Copy link
Member

alexander-akait commented Aug 17, 2020

webpack.config.js

module.exports = {
    mode: 'development',
    devtool: 'source-map',
    entry: './src/main/index.js',
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'bundle.js'
    },
    resolve: {
        alias: {
            app: [path.join(__dirname, 'src/main'), path.join(__dirname, 'src/foo')]
        }
    }
};

index.js

import a from 'app/widgets/a';
import b from 'app/widgets/b';
import c from 'app/widgets/c';

console.log('\nstatic import\n');

a();
b();
c();

console.log('\ndynamic import\n');

const load = id => import(/* webpackMode: "eager" */ `app/widgets/${id}`);

load('a').then(ad => ad.default())

    .then(() => load('b'))
    .then(bd => bd.default())

    .then(() => load('c'))
    .then(cd => cd.default())

    .catch(err => console.log(err));

Reproducible test repo - https://github.com/homobel/webpack5-dynamic-import

Ref: #9802 (comment)

@alexander-akait
Copy link
Member Author

/cc @vankop

@Zuckjet
Copy link

Zuckjet commented Oct 8, 2020

@sokra @evilebottnawi I am glad to try to fix this issue, and I want to have a discussion here to make sure I don't misunderstand this issue before sending a PR.

when createing a ContextModule new ContextModule(result.resolveDependencies, result)

the result params is a string which valuse is "xxx/src/main/widgets", so resolveDependencies function in ContextModuleFactory.js just read files under "main/widgets" directory . And thus not including files under "foo/widgets" directory.

In order to fix this issue, it seems I should make changes in two repo, both webpack and enhanced-resolve.

  1. Since the result param in new ContextModule(result.resolveDependencies, result) is resolved by alias plugin in enhanced-resolve, I should make it return array not string in this situation.
  2. The resolveDependencies function in ContextModuleFactory.js should be able to handle array.

@alexander-akait
Copy link
Member Author

/cc @sokra

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member Author

bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@alexander-akait
Copy link
Member Author

Reverted

@vankop
Copy link
Member

vankop commented Mar 23, 2022

merged again =)

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

Successfully merging a pull request may close this issue.

4 participants