Skip to main content

4-17

1 如何管理多包?

文章地址:https://medium.com/@NiGhTTraX/how-to-set-up-a-typescript-monorepo-with-lerna-c6acda7d4559

项目示例:https://github.com/NiGhTTraX/ts-monorepo

image-20220420082427941

npm私服

image-20220420083041144

执行命令

# 执行所有包中的test命令
lerna run test

# 只执行uilib中的test命令
lerna run test --scope uilib

eslint和prettier

image-20220420084235434

image-20220420084722583

image-20220420084754642

[1] https://www.bilibili.com/video/BV1s44y1C7an

2 cra删除console

craco.config.js

/* eslint-disable @typescript-eslint/no-var-requires */
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
const ForkTSCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig.paths.json')
const path = require('path')

module.exports = {
eslint: { enable: false },
webpack: {
configure: (config) => {
// Remove ModuleScopePlugin which throws when we try to import something
// outside of src/.
config.resolve.plugins.pop()

// Resolve the path aliases.
config.resolve.plugins.push(new TsconfigPathsPlugin())

// Let Babel compile outside of src/.
const oneOfRule = config.module.rules.find((rule) => rule.oneOf)
const tsRule = oneOfRule.oneOf.find((rule) => rule.test.toString().includes('ts|tsx'))

tsRule.include = undefined
tsRule.exclude = /node_modules/

// remove console
if (process.env.NODE_ENV === 'production') {
// remove console in production
const TerserPlugin = config.optimization.minimizer.find((i) => i.constructor.name === 'TerserPlugin')
if (TerserPlugin) {
TerserPlugin.options.terserOptions.compress['drop_console'] = true
}
}

// set alias
config.resolve = {
...config.resolve,
alias: {
...config.resolve.alias,
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.d.ts'],
}

return config
},
plugins: {
remove: [
// This plugin is too old and causes problems in monorepos. We'll
// replace it with a newer version.
'ForkTsCheckerWebpackPlugin',
],
add: [
// Use newer version of ForkTSCheckerWebpackPlugin to type check
// files across the monorepo.
new ForkTSCheckerWebpackPlugin({
issue: {
// The exclude rules are copied from CRA.
exclude: [
{
file: '**/src/**/__tests__/**',
},
{
file: '**/src/**/?(*.)(spec|test).*',
},
{
file: '**/src/setupProxy.*',
},
{
file: '**/src/setupTests.*',
},
],
},
}),
],
},
},
jest: {
configure: {
preset: 'ts-jest',

moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
// This has to match the baseUrl defined in tsconfig.json.
prefix: '<rootDir>/',
}),
},
},
}

[1] https://stackoverflow.com/questions/56276325/how-can-remove-console-log-in-the-production-build-of-a-react-application-create

3 remix传入数组参数

# 正确
["0xAd510519008772007d3458502EF26D831BEDb155"]

# 错误
['0xAd510519008772007d3458502EF26D831BEDb155']

4 导出sol文件

带依赖的导出sol文件

npx hardhat flatten contracts/GeneralStaker.sol  > staker.sol

5 git branch批量删除

git branch -d `git branch --list 'ref/*'`

[1] Can you delete multiple branches in one command with Git?.https://stackoverflow.com/questions/3670355/can-you-delete-multiple-branches-in-one-command-with-git

6 uniswap价格影响计算

TODO

7 eslint批量自动修复

npx eslint -c ./.eslintrc.json --fix ./packages/klein-uilib/src/**/**.(ts|tsx)
"resolutions": {
"babel-loader": "8.1.0"
},

8 peerDependencies有什么用?

它会告诉npm:如果某个package把我列为依赖的话,那么该package也必需应该有对peerDependencies依赖进行安装

[1] 探讨npm依赖管理之peerDependencies.https://www.cnblogs.com/wonyun/p/9692476.html

9 年利率(APR)与年溢率(APY)

APR = r x N
// r:当年的利率;
// N:利息期(N = 1,表示1年)
APY = (1+r)^n - 1
// r:当期利率;
// n:利息期(n=1 表示 1 天)

[1] 年利率(APR)与年溢率(APY).https://zhuanlan.zhihu.com/p/383055488

10 mysql连接问题

Create new user with host '%' rather than localhost. Below is works for me. It may useful to you.

mysql> CREATE USER 'usernameall'@'%' IDENTIFIED BY 'ThePassword';
mysql> grant all on *.* to 'usernameall'@'%';

connect mysql use port

mysql -u root -P 3040 -h 192.168.3.134 -p 

[1] Host '172.18.0.1' is not allowed to connect to this MySQL server.https://github.com/docker-library/mysql/issues/275

grant all privileges on *.* to 'root'@'%' identified by 'root';