- npm v7 is required to use
npm-set-script
command (see npm doc)
- I use
run-s
for its side effect of using the same package manager as the user to run subsequent scripts while being a cross OS solution as opposed to$npm_execpath
(seenpm-run-all
doc) - I use
esm
for JS project to provide support for esm modules syntax (seeesm
doc) - I use
nodemon
to run and watch the source code for change in dev mode (seenodemon
doc)
yarn init -y
mkdir src
echo "console.log('Hello world');" >./src/index.js
echo "require('./src');" >./index.js
npm set-script start "node -r esm src"
npm set-script dev "nodemon --watch src start"
yarn add esm
yarn add -D nodemon
npm init -y
mkdir src
echo "console.log('Hello world');" >./src/index.js
echo "require('./src');" >./index.js
npm set-script start "node -r esm src"
npm set-script dev "nodemon --watch src start"
npm i -S esm
npm i -D nodemon
yarn init -y
mkdir src
echo "console.log('Hello world');" >./src/index.ts
echo "require('./dist');" >./index.js
npm set-script start "node dist"
npm set-script build "tsc --outDir dist"
npm set-script dev:build "tsc --watch --outDir dist"
npm set-script dev:ready "wait-on dist/index.js"
npm set-script dev:start "nodemon --watch dist start"
npm set-script dev "concurrently \"run-s dev:build\" \"run-s dev:ready dev:start\" -n build,run"
yarn add typescript
yarn add -D nodemon wait-on concurrently npm-run-all
yarn tsc --init
npm init -y
mkdir src
echo "console.log('Hello world');" >./src/index.ts
echo "require('./dist');" >./index.js
npm set-script start "node dist"
npm set-script build "tsc --outDir dist"
npm set-script dev:build "tsc --watch --outDir dist"
npm set-script dev:ready "wait-on dist/index.js"
npm set-script dev:start "nodemon --watch dist start"
npm set-script dev "concurrently \"run-s dev:build\" \"run-s dev:ready dev:start\" -n build,run"
npm i -S typescript
npm i -D nodemon wait-on concurrently npm-run-all
./node_modules/.bin/tsc --init
yarn init -y
mkdir src
echo "console.log('Hello world');" >./src/index.ts
echo "require('./dist');" >./index.js
npm set-script start "node dist"
npm set-script build "tsc --outDir dist"
npm set-script dev:start "ts-node src"
npm set-script dev "nodemon --watch src --exec \"run-s dev:start\""
yarn add typescript
yarn add -D nodemon ts-node npm-run-all
yarn tsc --init
npm init -y
mkdir src
echo "console.log('Hello world');" >./src/index.ts
echo "require('./dist');" >./index.js
npm set-script start "node dist"
npm set-script build "tsc --outDir dist"
npm set-script dev:start "ts-node src"
npm set-script dev "nodemon --watch src --exec \"run-s dev:start\""
npm i -S typescript
npm i -D nodemon ts-node npm-run-all
./node_modules/.bin/tsc --init
Sourced as an alias, it can be used to quickly init your project. Pass a name argument to define a target directory.
initProject() {
if [ "$#" -ne 1 ]; then
echo "One argument required: target directory name"
return 1
elif [[ -d "./$1" ]]; then
echo "Target directory already exists: $1"
return 1
else
mkdir $1
cd $1
# Your commands of choice go here
fi
}
Example usage: initProject my-project