- Create new repo on Github
- cd into the appropriate parent directory and clone repo locally via the command-line interface. For example:
cd ~/path/to/directory git clone git@github.com:username/repo-name.git
code directory-name
to open new workspace in VSCode for the new repo (or use the File menu)- Write
README.md
and make first commit npm init -y
to initializepackage.json
file- If running project in Node.js, add
"type": "module"
topackage.json
file in order to use ES6 modules echo node_modules/> .gitignore
to create a.gitignore
withnode_modules/
added
npm install webpack webpack-cli --save-dev
to install webpack- Set up
src/
anddist/
directories - Create
index.js
withinsrc/
directory - Create
index.html
andstyle.css
withindist/
directory - Link to
style.css
andmain.js
inindex.html
- Create a
webpack.config.js
file:const path = require('path'); module.exports = { entry: './src/index.js', mode: 'development', output: { filename: 'main.js', path: path.resolve(__dirname, 'dist'), }, };
- In
package.json
add the following lines to the"scripts"
object:"build": "webpack", "build-watch": "webpack --watch"
Reference: https://github.com/babel/babel-loader
Reference: https://blog.jakoblind.no/babel-preset-env/
Reference: https://browsersl.ist/
npm install --save-dev @babel/core @babel/cli
to install Babelnpm install --save-dev @babel/preset-env
to install a presetnpm install --save-dev babel-loader
to allow transpiling JavaScript files using Babel and webpackecho -e "{\n \"presets\": [\"@babel/preset-env\"]\n}"> .babelrc
to create a.babelrc
file and configure the"presets"
section. When opened, it should look like the following:{ "presets": ["@babel/preset-env"] }
- In
webpack.config.js
add the following to themodule.exports
object:module: { rules: [ { test: /\.(?:js|mjs|cjs)$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: {} } } ] }
echo \>0.25% and not dead> .browserlistrc
to create a.browserlistrc
file and add>0.25% and not dead
(or compose otherwise as needed)
echo "dist/* linguist-vendored=false"> .gitattributes
to create a.gitattributes
file and adddist/* linguist-vendored=false
Reference: https://gist.github.com/ManonLef/2d3de90cbbdf9db563cbc786c21ae1cc
Reference: https://medium.com/@kiran.jasvanee/prettier-auto-formatting-in-visual-studio-code-beab1c026b13
npm install --save-dev --save-exact prettier
echo -e "{\n \"singleQuote\": true\n}"> .prettierrc.json
to create a.prettierrc.json
file (needed to recognize this repo uses prettier). When opened, it should look like the following:{ "singleQuote": true }
echo -e "node_modules/\ndist/main.js"> .prettierignore
to create a.prettierignore
file withnode_modules/
anddist/main.js
included (or compose otherwise as needed)- (Be sure Prettier VSCode extension is installed)
- Within the
.vscode
directory, create asettings.json
file and add the following in order to format on save:
Or open workspace settings wih VSCode command palette, go to "Workspace" tab, select "Text Editor" dropdown, select "Formatting", check "Format on Save"{ "editor.formatOnSave": true }
Reference: https://eslint.org/docs/latest/use/getting-started
Reference: https://www.digitalocean.com/community/tutorials/linting-and-formatting-with-eslint-in-vs-code
npm init @eslint/config
to initialize ESLint and create config file- Configure the resulting
.eslintrc.*
file via the prompts - (Be sure ESLint VSCode extenion is installed)
- Customize the
.eslintrc.*
"rules"
object. For example:"rules": { "consistent-return": "off", "import/extensions": ["error", "always"], "no-console": "off", "no-else-return": ["error", { "allowElseIf": true }], "no-param-reassign": ["error", { "props": false }], "no-plusplus": "off", "no-unused-expressions": ["error", { "allowTernary": true }], "no-use-before-define": ["error", { "functions": false, "classes": false }] }
npm install --save-dev eslint-config-prettier
to make ESLint and Prettier work together without conflict- Add
"prettier"
to the end of the"extends"
array in your.eslintrc.*
file. For example:"extends": [ "airbnb-base", "prettier" ],
npx eslint-config-prettier path/to/main.js
to see if there are conflicts (replacepath/to/main.js
with your main.js file path)
Reference: https://jestjs.io/docs/getting-started
npm install --save-dev jest
to install Jest- Add the following to the
"scripts"
object in yourpackage.json
file:"test": "jest", "test-watch": "jest --watch *.js",
- Add the following to your
.eslintrc.*
file:"overrides": [ { "files": [ "**/*.test.js", "**/*.test.jsx" ], "env": { "jest": true } } ],
Reference: https://jestjs.io/docs/en/getting-started#using-babel
npm install --save-dev babel-jest @babel/core @babel/preset-env
to install the babel-jest dependency- Update the contents of your
.babelrc
file to look like the following:{ "presets": [["@babel/preset-env", { "targets": { "node": "current" } }]] }