How to transpile JS for the WordPress world?

Question

I have a simple file that I wanna use as dependency for other scripts:

export const postRequest = () => {}

Cool! I’m using the following build command:

"build:cjs": "npx babel --plugins @babel/plugin-transform-modules-commonjs ./src/index.js --out-file ./dist/growth-ajax.cjs.js --source-maps"

To build a Common JS version of the script but when I’m trying to use it, I’m given the Uncaught SyntaxError: Unexpected token 'export' error.

What exactly is the common way of transpiling code so that it’s ready and good for the WP environment?

0
Daniel James 2 months 2021-05-15T13:54:15-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse