by Markus Hatvan
{
"scripts": {
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('You must use Yarn to install, not NPM')\""
},
}
force use of npm/yarn
specify required version (node, npm, yarn)
{
"engines": {
"node": "^8 || ^10",
"npm": "<5",
"yarn": "1.22.0"
},
}
always use pinned, reproducable dependencies for CI
yarn install –frozen-lockfile
or
npm ci
much wow!
999x faster!
awesome!
When upgrading dependencies:
of course also run lint, test, e2e and manual check
react-navigation -> @react-navigation/native
babel-cli -> @babel/cli
create PACKAGE.md for files that cannot be updated atm
"typescript": "2.7.2"
keep locked until angular is compatible with typescript >= 2.8.0
"webpack": "3.11.0"
wait until 3rd party plugins support webpack v4
up to date, but not really...
npm is at least as fast as yarn again
npm install -> npm i
npm uninstall -> npm r
issues with merge conflicts in package-lock.json?
no clue how to solve it?
npm doctor
npm audit (fix)
Don't despair!
npx npm-merge-driver install --global
check for unused dependencies in package.json with npm-check -> needs manual checking for false positives because it only looks for require or import statements
yarn
yarn v2 is RC27!!
yarn audit
upgrade deps with
yarn upgrade-interactive [--latest]
check for unused dependencies in package.json with yarn-check -> needs manual checking for false positives because it only looks for require or import statements
additionally to npm doctor, you can run
npx @yarnpkg/doctor
Random tips & tricks
use lodash-es instead of lodash (tree-shakable)
replace moment.js with date-fns, etc.
use optional chaining operator
use nullish coalescing when working with numbers instead of truthy checking
dont have to support old browsers? -> investigate transpiling to es6 instead of es5, see https://kangax.github.io/compat-table/es6/
scss -> use @import '~bootstrap' instead of '../../../node_modules/bootstrap'
use json-server or jsonplaceholder for mock data
use precommit lint/format hook to keep consistency within team
create-react-app can be created with typescript now
when lazy loading modules with webpack, you can name them: import(/* webpackChunkName: "print" */ './print')
presented at Angular Vienna