Using Napacitor with Legacy Build Chains (Vue CLI 4 / webpack 4)
Napacitor's npm packages ship as CommonJS with .d.ts type declarations (dist/ CJS + d.ts, built in strict TypeScript mode). Unlike ESM-only libraries, they work out of the box with older, traditional build chains such as Vue CLI 4 and webpack 4 — no transpilation exceptions, no fullySpecified hacks, no bundler upgrades required.
This is a deliberate design decision and a differentiator: you can add native app delivery to an existing legacy web project without modernizing its build chain first.
Requirements
Your project needs the usual Napacitor baseline:
- A
package.jsonwith a build script producing a web assets directory (e.g.dist/); - An
index.htmlat the root of that directory; - Node.js 18+ (for the
napCLI — the app's own build chain keeps whatever it uses).
Adding Napacitor to a Vue CLI 4 project
Vue CLI 4 projects use webpack 4 under the hood, which resolves CJS modules natively.
npm i @napacitor/core
npm i -D @napacitor/maui @napacitor/cli
Napacitor beta releases declare peer dependencies like @napacitor/core@^0.1.0. If strict npm rejects the combination, install with npm install --legacy-peer-deps — see Troubleshooting.
Initialize and configure webDir to point at the CLI's output directory:
npx nap init com.example.app "My App" --web-dir dist
Generate the host and run:
npm run build # vue-cli-service build → dist/
npx nap add maui # generate the MAUI host (auto-syncs when dist/ exists)
npx nap run --target android # or windows / ios / maccatalyst
webpack 4 specifics
- CJS output: all
@napacitor/*packages resolve via theirmainfield (dist/index.js, CommonJS). webpack 4 requires no configuration for them. - No ESM-only transitive dependencies: the core runtime and plugins depend only on
@napacitor/core; there are no modern-only packages in the tree that webpack 4 cannot parse. - Dynamic web implementations: plugin web fallbacks are loaded lazily (
import()), which webpack 4 supports natively (it creates a split chunk).
Keeping the old chain healthy
- If your webpack 4 project predates
es2017syntax support, the same Babel pipeline you already run covers@napacitor/*code — the shipped JS targets the same era as Capacitor (ES2017). - Upgrading the build chain is never required for Napacitor to work; it is only ever an independent improvement you may make on your own schedule.