Issue 1:
Feature request

What is the expected behavior?

Following the definition inside the docs:

https://webpack.js.org/api/module-methods/#import-1

We can use static paths inside dynamic imports, to search matching files inside a specific folder / files tree.

Example:

importApp(path) {
return import(
/* webpackInclude: /\/app.mjs$/ */
/* webpackExclude: /\/node_modules/ */
/* webpackChunkName: "chunks/[request]" */
/* webpackMode: "lazy" */
`../../${path}`
);
}

What is motivation or use case for adding/changing the behavior?

There are use cases (especially for the neo.mjs context), where the base path can be in different spots.

In case I want to build the framework repo itself to get split chunks for all apps & examples, I need to path specified above ("../../").

We have the structure:

neo

apps

examples

src

worker

App.mjs

Since the AppWorker is the main entry point for all apps, we need to walk 2 folders upwards.

Now, when we use npx neo-app to generate a new app (workspace), the folder structure is different:

workspace

apps

node_modules

neo.mjs

src

worker

App.mjs

In this case, we want to parse all apps inside the apps top level folder, while ignoring the apps & examples folder inside the neo.mjs repo itself. Ignoring the repo works fine with the webpackExclude here.

To make it work, I needed to create a copy of the AppWorker class, just to change the webpack based imports:

https://github.com/neomjs/neo/blob/dev/buildScripts/webpack/entrypoints/AppWorker.mjs

Extending the real AppWorker class can not work, since in this case, webpack would parse the overridden imports as well.

importApp(path) {
if (!Neo.config.isExperimental) { // dist/dev & dist/prod
return import(
/* webpackInclude: /\/app.mjs$/ */
/* webpackExclude: /\/node_modules/ */
/* webpackChunkName: "chunks/[request]" */
/* webpackMode: "lazy" */
`../../../../../${path}`
);
} else {
return import( // dev mode
/* webpackIgnore: true */
`../../../${path}`
);
}
}

It actually needs 2 different versions for this one directly (running inside the browser VS using webpack based builds).

It does work fine with the duplicated app worker file, but I think it should be easier to achieve this.

How should this be implemented in your opinion?

I am not 100% sure, what the best approach could be.

We could add a specific variable name, which would need to get resolved inside the webpack based builds.

E.g.: ${basePath}../../${path}

To keep it reasonable, the variable has to get defined inside the same scope.

importApp(path) {
let basePath = '';

if (myCustomEnv === true) { // this is the tricky part => figuring out which version to use
basePath = '../../../';
}

return import(
/* webpackInclude: /\/app.mjs$/ */
/* webpackExclude: /\/node_modules/ */
/* webpackChunkName: "chunks/[request]" */
/* webpackMode: "lazy" */
`${basePath}../../${path}`
);
}

Are you willing to work on this yourself?

Ugh, if I just had more time. Willing to provide feedback for sure.

Issue 2:
Bug report

What is the current behavior?

When requiring files using import.meta.webpackContext (added in #15446) that are located within a node_modules folder, eg:

const vuetify = import.meta.webpackContext('vuetify/lib/locale', {
recursive: false,
regExp: /(en|hu)\.js$/i,
});

It doesn't work properly and throws a warning during compilation

WARNING Compiled with 2 warnings 6:40:36 PM

warning in ./node_modules/vuetify/lib/locale/ ./node_modules/vuetify/lib/locale/ sync nonrecursive (en%7Chu)\.js$/

Module not found: Error: Can't resolve 'webpack-meta-bug/node_modules/vuetify/lib/locale/vuetify/lib/locale/en.js' in 'webpack-meta-bug'

It seems to be adding the context path twice to the request

If the current behavior is a bug, please provide the steps to reproduce.

https://github.com/Tofandel/webpack-meta-bug

Use the following webpack config

const path = require('path')
module.exports = {
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, './node_modules'),
]
},
}

And use import.meta.webpackContext('some_package_files')

What is the expected behavior?

It should require the files correctly

Other relevant information:

webpack version: 5.70.0

Node.js version: 16.13.1

Operating System: WSL2 - Ubuntu 20.04

Additional tools: