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

All elm apps rebuild on each change #132

Open
michaeljones opened this issue Feb 7, 2018 · 6 comments
Open

All elm apps rebuild on each change #132

michaeljones opened this issue Feb 7, 2018 · 6 comments

Comments

@michaeljones
Copy link

michaeljones commented Feb 7, 2018

This might be a peculiarity of my setup but I have 4 separate elm apps being built by webpack and when ever I make a change all 4 rebuild. Even when the change is to a file that is only used by one of them.

The rebuilding can be quite quick for 3 of the 4 apps but it is still slows down the experience.

I see output like this on a typical file change:

[1354] ./node_modules/moment/locale ^\.\/.*$ 2.86 kB {27} [optional] [built]
    + 1495 hidden modules
 46% building modules 6/10 modules 4 active ...erver/apps/business/src/Locations.elmStarted compiling Elm..
 52% building modules 7/10 modules 3 active ...erver/apps/business/src/Locations.elmStarted compiling Elm..
 57% building modules 8/10 modules 2 active ...erver/apps/business/src/Locations.elmStarted compiling Elm..
 64% building modules 9/10 modules 1 active ...erver/apps/business/src/Locations.elmStarted compiling Elm..
 94% asset optimization

Though interestingly, src/Locations.elm is only one of the 4 elm entry files. Not sure why that name is printed out each time.

My set up is that I have a single folder (server/apps/business) which has a elm-package.json and 4 typescript files. Each of those typescript files requires a different .elm file from the src subdirectory in server/apps/business.

My webpack elm rule looks like:

                {
                    test: /\.elm$/,
                    exclude: [/elm-stuff/, /node_modules/],
                    use: [
                        'elm-css-modules-loader',
                        {
                            loader: 'elm-webpack-loader',
                            options: {
                                debug,
                                cwd: path.join(__dirname, '..', 'server', 'apps', 'business'),
                                pathToMake
                            }
                        }
                    ]
                },

I've tried looking at the code. I get the feeling that it is watching all *.elm files and rebuilds everything if any of them changes rather than following imports from each entry .elm file. Understandable if that is the case but I wanted to check in case the behaviour I'm seeing is avoidable with some configuration changes.

Thanks for the project. It has made it much easier to add elm into my stack at work.

@DawidJanczak
Copy link

Is it possible it's connected to #123? I'm curious if commenting this line https://github.com/elm-community/elm-webpack-loader/blob/master/index.js#L135 would fix it for you the same way it does for me.

@joecorkerton
Copy link

I am having the same issue with what sounds like a similar file structure. Tried commenting out various lines but nothing seemed to help. Not a deal breaker but would be nice to have it fixed

@szubtsovskiy
Copy link

I've run into the same issue and finally got it resolved by removing cwd option from elm-webpack-loader. Seems working fine though I don't know if it was a time bomb as this option is recommended.

@gavin667
Copy link

gavin667 commented Oct 2, 2019

We also just managed to get this working by removing the cwd option as well.

We did run into an issue were some files were not compiling when file dependencies changed but this was due to some files not having the proper namespaced module name in the main elm file that was initialised in the Javascript. These files shouldn't have been compiling from the start because of the module name but because the cwd adds all of these file as dependencies of each other they compiled regardless.

@michaeljones
Copy link
Author

Interesting to read. I've just tried removing the cwd option but then I get errors saying it cannot find elm.json. I am using the elm 0.19.1 beta but I assume the issue would be the same. I run webpack from the top of my project whilst the elm.json is in an apps folder along with the elm code (things have been moved around since I opened this issue.) I'll report back if I try moving the elm.json to the top level and running things from there.

@szubtsovskiy
Copy link

@gavin667 Thank you for sharing this experience! You saved my day yesterday. :-) I ran exactly into the same issue and because of reading your comment in the morning it took very short to fix it.

@michaeljones I am 99% sure that this problem is because elm.json is not in the same directory where you run Webpack. I also had to move it to the same folder where Webpack is to make the loader happy.

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

No branches or pull requests

5 participants