-
Notifications
You must be signed in to change notification settings - Fork 11
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
Setup eslint/prettier on docker + host #1
Comments
A solution (from this twitter thread) might be to:
|
The following resource may be useful as an intermediary step : https://nickjanetakis.com/blog/docker-tip-75-how-to-avoid-node-modules-in-your-volume-mounts |
I stumbled upon the same problem, which ends up being quite frustrating as all the workarounds I’ve seen so far are somewhat hacky. Edit: actually there is one elegant solution to it: |
I've been told about this solution. You're right @pierreyves-lebrun , this might be the first one true elegant way to solve that problem in a long time. cc @warpdesign |
TL;DR
This issue aims to describe how if you setup docker on a fullstack project, you may loose some developer experience like in-editor linting / formating + git hooks and propose a solution.
Without docker
Here is an example of how you would make an advanced setup of eslint/prettier (with husky for precommit hooks) on a regular frontend project without docker topheman/my-react-app-starter@9c0fa1b :
The husky/precommit hooks part will be addressed on an other issue.
With docker
First install prettier, eslint and a few eslint plugins because we want some advanced rules:
Note: We need to
docker-compose run --rm front
to run thenpm install
command inside the docker container, which is a Linux environment, because we are making the call from our host machine which could be a MacOS or a Windows (which means that some nativenode_modules
might differ and will need to be compiled on the right platform to run inside the docker container AND to save the proper versions on thepackage-lock.json
).Then we'll have to create a few files:
front/.eslintignore
:front/.eslintrc
:front/.prettierignore
:front/.prettierrc
:Add the following scripts to the
front/package.json
:That way, we will be able to run eslint and prettier from inside the docker container like this:
For example, the
lint
task will be run from inside the docker container (NOT from the host):Developer Experience
But this is not enough.
The things described above:
node_modules
are installed on the host, they are installed on the container (see docker-compose.override.yml where thefront-deps
modules is declared)eslint
of your working directory (and needed eslint plugins), same for prettierSolution
This means that we also need to install the
node_modules
on the host and not alterpackage-lock.json
file while installing.npm install
based onpackage-lock.json
, but ensure that it won't be updated in any way ?npm install
onpackage-lock.json
, because host platform and container platform may differ (if your on a Mac for example, you will have to install some optional modules likefsevents
)Further notes about Cypress and Husky
This is the same kind of problem for cypress and husky:
.git
at the rootThe text was updated successfully, but these errors were encountered: