Search code examples
javascriptnpmbrowserify

How to create a stand-alone, plain javascript minified version of the capacitor-community http module example


All I want is to take the example source code under Usage at https://github.com/capacitor-community/http and compile a standalone javascript file I can include in my app. I have already done npm install @capacitor-community/http and I do have a working CapacitorJS app.

I have tried browserify, and I get:

$ browserify test.js -o out.js

test.js:2
import '@capacitor-community/http';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

I have tried esbuild and I get:

$ ./node_modules/.bin/esbuild test.js --bundle --outfile=out.js
 > test.js:12:20: error: Expected ";" but found "Http"
    12 │   const ret = await Http.request({
       ╵                     ~~~~

1 error

My project is plain javascript, so I don't have a build pipeline set up (nor do I know how to do such a thing).


Solution

  • You need to use the CLI version of Babel to do this.

    https://babeljs.io/docs/en/babel-cli

    Try running

    npx babel test.js --out-file out.js