npm install -D acorn babel-loader @babel/core @babel/preset-env babel-polyfill webpack webpack-cli uglifyjs-webpack-plugin --save-dev
webpack-cli
and acorn
are dependencies that you, unfortunately, have to install if you want to run this god damn thing without any obscure warnings or errors.
That's where things become annoying and why I've written this document. Simply paste the next file called webpack.config.js
into a new file with the same name which should be place under your project's root folder.
Add the following scripts in your package.json
:
{
"scripts": {
"build": "WEBPACK_ENV=build webpack",
"dev": "WEBPACK_ENV=dev webpack"
}
}
The difference between dev
and build
is that build
adds JS uglification to make the production code smaller.
To build your production code, run:
npm run build
To build your dev code, run:
npm run dev
Make sure there is a main file (e.g., index.js
) that will export all your APIs. Example:
index.js
// Some code here...
module.exports = {
yourAPIfn_01,
yourAPIfn_02
}
Use NodeJs specific libraries like fs
. Those libs are designed to run in Node only. They cannot be transpiled.
lol at your description but extremely helpful to start!