现在前端生产环境的代码基本上是压缩的,如果需要知道压缩代码报错对应的源码位置,我们可以通过sourcemap文件去实现。但对于前端而言,如果把sourcemap放出来,差不多相当于把源码暴露出来了。为了解决这个问题,我把sourcemap文件放到服务端,然后将浏览器的报错发送到服务端由服务端根据错误信息去定位源码所在位置。以前用过Sentry,好像是支持的,但我还有一些其他额外的需求,所以我就造了个简易的轮子。
现在前端项目或多或少会用到Git
、Typescript
、Eslint
、Husky
、Lint-staged
。本文记录一下如何在项目中使用这些工具。
环境要求:
- 已安装git
- 已安装Node和Npm
- npm全局安装typescript和eslint
注意:以下操作命令均在项目目录下执行
在前端项目开发时,本地启动项目可能使用的地址localhost+端口,然后后端给出的api接口可能是外网的地址(例如dev.api.com),前端直接使用可能会存在跨域问题,解决方法有两种:一种是后端直接设置允许跨域,另一种是做反向代理。 前端做反向代理可以使用NGINX,也可以使用webpack-dev-server。使用webpack-dev-server做代理的配置如下:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://dev.api.com',
pathRewrite: {'^/api' : ''}
}
}
}
}
华为镜像源
NPM的配置文件为用户根目录下的:~/.npmrc
(Windows路径为:C:\Users\<UserName>\.npmrc
),您可以点击此处直接下载配置文件,或者运行如下命令设置:
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
npm cache clean -f
华为开源镜像站同时也提供了工具类加速镜像,可以通过如下的命令设置加速地址: ※ 设置nodejs工具的镜像地址
npm config set disturl https://mirrors.huaweicloud.com/nodejs
直接npm i puppeteer
会报错的。
自己乱搞一波,不知道怎么安装好了。大概有以下操作:
sudo apt install snapd
- 重启设备
sudo apt install chromium-browser chromium-codecs-ffmpeg
npm i puppeteer
sudo sysctl -w kernel.unprivileged_userns_clone=1
- 重启设备
创建配置文件
执行命令: sudo vim /etc/mongodb/mongod.conf
并添加以下内容
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
storage:
dbPath: /var/lib/mongo
net:
bindIp: 127.0.0.1
Export and import directives have several syntax variants.
In the previous article we saw a simple use, now let’s explore more examples.
Export before declarations
We can label any declaration as exported by placing export before it, be it a variable, function or a class.
For instance, here all exports are valid:
// export an array
export let months = ['Jan', 'Feb', 'Mar','Apr', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// export a constant
export const MODULES_BECAME_STANDARD_YEAR = 2015;
// export a class
export class User {
constructor(name) {
this.name = name;
}
}