aurelia / aurelia/webpack-plugin
Aurelia adds /index to modules path after ModuleConcatenationPlugin
- Dominant language
- TypeScript
- Stars
- 89
- Forks
- 33
- PR merge metrics
- No merged PRs in 30d
Description
**I'm submitting a bug report**
* **Library Version:**
3.0.0
**Please tell us about your environment:**
* **Operating System:**
OSX 10.13.6
* **Node Version:**
10.15.3
* **NPM Version:**
6.4.1
* **JSPM OR Webpack AND Version**
webpack 4.29.1
* **Browser:**
all
* **Language:**
ESNext
**Current behavior:**
When using `.plugin(PLATFORM.moduleName('my/plugin/path'))` on a production build, where `ModuleConcatenationPlugin` runs by default, the module ends up on the bundle with the key `my/plugin/path/index`, so the app fails to run as `my/plugin/path` doesn't exist.
**Expected/desired behavior:**
On the main `configure` of the app, use `.plugin` for a local folder index file that includes a component/service/valueConverter, basically anything that the `ModuleConcatenationPlugin` may want to optimize:
```js
// main.js
export const configure = (aurelia) => {
aurelia.use
.plugin(PLATFORM.moduleName('modules/my-module'))
.standardConfiguration();
return aurelia.start().then(() => aurelia.setRoot(...));
};
// modules/my-module/index.js
import { MY_CONSTANT } = './my-constant.js';
export const configure = (aurelia) => {
console.log(MY_CONSTANT);
};
// modules/my-module/my-constant.js
export const MY_CONSTANT = {
someKey: 'someValue',
};
```
That's enough for `ModuleConcatenationPlugin` to try to put `my-constant` inside `my-module/index.js` and for the `PreserveModuleNamePlugin` to change `modules/my-module` to `modules/my-module/index`.
* **What is the expected behavior?**
For `PreserveModuleNamePlugin` not to add the `/index`.
* **Possible solution**
Not sure if this is the right way to do it, but if we add the following code before [this line](https://github.com/aurelia/webpack-plugin/blob/master/src/PreserveModuleNamePlugin.ts#L61), it works:
```js
if (id.endsWith('/index') && !realModule.rawRequest.endsWith('index')) {
id = id.replace(/\/index$/, '');
// or id = id.substr(0, id.length - 6);
}
```
I'm not that familiar with the module structure, so I'm not sure if we can "trust" in `rawRequest`
Contributor guide
Research direction
Start with src/PreserveModuleNamePlugin.ts around line 61 and reproduce the production build using ModuleConcatenationPlugin with a local folder index module. Inspect how the module id and rawRequest are handled when the bundle key gains /index. Done means the configured module remains addressable as my/plugin/path rather than my/plugin/path/index.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, webpack
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100