-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Unexpected behavior with monorepo #145
Comments
A workaround for this can be to define ...
resolve: {
alias: {
'services': path.resolve(__dirname, "../services"), ...
} ...
}, ... However, this can also be cumbersome when there are several shared modules. |
I've had problems with monorepo recently as well. I am not sure what the best solution here is. Any idea is welcome. Maybe I should add a mono-repo mode to the plugin? If I try to sum up the options so far:
|
@jods4 I indeed However, when one uses yarn (workspace) + lerna, all dependencies for all projects in a monorepo can be hoisted in the root And regarding the dedupe webpack plugin, I think it is long deprecated in favor of |
as far as I remember there are options in yarn workspaces to keep some of the modules.. not hoisted.. |
@Alexander-Taran With yarn workspace, it works properly. In that setup as well, one need to use |
I might be having a similar issue. My structure is something like this:
from within the webpack config of each app, I'm adding the common directory as a module and alias: resolve: {
extensions: ['.js'],
modules: [path.resolve(__dirname, '../common'), 'src', 'node_modules'],
alias: {
common: path.resolve(__dirname, '../common')
}
}, Despite the common modules being resolved and loaded by the individual apps, the modules doesn't seem like they're getting transpiled by babel since I'm getting syntax errors:
My commons dir doesn't compile itself. It's literally just all the source files since I expect the apps using them to compile these along with everything else. These common modules can't go on their own builds, since Sass files inside Btw, all the solutions at babel/babel-loader#293 doesn't seem like they work for my case. |
@jemhuntr I think this is a different issue. You have not specified if you are using lerna or not. If not you may benefit from using something like lerna or yarn workspace. I would suggest to build your common module as an npm package. If there are some app specific stuffs inside your common module, then it is not really common. If you want to style your apps and put all css in a common stylesheet, then a better alternative would be to use css modules. Here are some resources for css module:
Then you can build your common module and use lerna to add it to your apps. That way the common module will reside in Hope this helps. |
@Sayan751 Yeah, I'm not using lerna nor do I have a monorepo structure. This is just the most relevant resource I found about the specific issue, and I figured out eventually that the issue is most likely with webpack upstream. And thanks, CSS Modules is definitely the way to go. The last time I tried getting it to work didn't exactly go well though, but I might try it again on my next project. I really just have been looking for an easy way to share local resources between multiple webpack builds, as the apps are literally just copy-pastes of each other with different implementations and content structure. |
I'm submitting a bug report
3.0.0-rc.1
Please tell us about your environment:
Operating System:
Windows 10
Node Version:
6.11.2 | 8.10.0
3.10.10 | 5.6.0
webpack 4.5.0
Browser:
Chrome 65.0.3325.181 | Firefox 59.0.2 | Edge 41.16299.371.0
Language:
TypeScript 2.8.1
Current behavior:
The plugin is not working as expected when packages are symlinked. To demonstrate the behavior, I have created a repository. I have a monorepo (using lerna) with following structure:
If I want to register some module specific routes from
myplugin
, I need to useWith this, the webpack build for
main
works iff I setresolve.symlinks: false
in my webpack config. However, this causes another problem which portrays as if the DI is failing. To clarify, let's assume that there is aMyService
exported fromservices
package, which is used in bothmain/main.ts
andmyplugin/index.ts
withContainer.instance.get
. Now, one would expect that same instance will be provided in both the places. However, that is not the case asMyService
is being resolved from 2 different sources:main/main.ts
: frommain/node_modules/services/...
myplugin/index.ts
: frommain/node_modules/myplugin/node_modules/services/...
(as compiled frommain
)And this problem can only be resolved using
resolve.symlinks: true
, which provides unique path for both cases. One can verify using the provided repository and tweaking the configurations.Expected/desired behavior:
What is the expected behavior?
The expected behavior is that one configuration should support both the cases. Also if possible, please add documentation/best practices for monorepo.
What is the motivation / use case for changing the behavior?
In a monorepo application one would ideally like to symlink the local dependencies, so that a simple
watch
task to build the sources, makes the changes immediately available for the running application.The text was updated successfully, but these errors were encountered: