Install npm_ex
Add :npm to your Mix dependencies:
def deps do
[{:npm, "~> 0.7.0"}]
endFetch dependencies:
mix deps.get
Create package.json
For a new project:
mix npm.init
This creates a minimal package.json in the project root.
If your project already has a package.json, npm_ex will use it directly.
Add dependencies
mix npm.install lodash
mix npm.install @types/node@^20
mix npm.install eslint --save-dev
npm_ex updates package.json, resolves the dependency graph, downloads packages into the global cache, links node_modules/, and writes npm.lock.
Install existing dependencies
mix npm.install
Use this after editing package.json or cloning a project.
Run package binaries
Executables from package bin fields are linked into node_modules/.bin/:
mix npm.exec eslint .
Run package scripts
{
"scripts": {
"build": "vite build"
}
}mix npm.run build
Commit files
Commit:
package.jsonnpm.lock
Do not commit node_modules/.
CI install
Use frozen mode in CI so lockfile drift fails the build:
mix npm.ci
Equivalent:
mix npm.install --frozen
See CI and reproducibility for a full workflow.