Skip to main content

9 posts tagged with "js"

View All Tags

· One min read

npm install -g pm2

for java

{
"name": "j-a",
"script": "java",
"args": [
"-jar",
"base-eureka/build/libs/base-eureka-1.0.jar"
],
"exec_interpreter": "",
"exec_mode": "fork"
}

npm install -g pm2

for k3s

{
"name": "k3s",
"script": "k3s",
"args": [
"server",
"--docker"
],
"exec_interpreter": "",
"exec_mode": "fork"
}

pm2 start pm2.json

log

~/.pm2/logs

常用

pm2 ls
pm2 start app
pm2 stop app
pm2 delete app
pm2 restart app

· One min read

编写简洁漂亮,可维护的 React 应用 https://github.com/shimohq/react-cookbook

  • 前言
  • 组件声明
  • 计算属性
  • 事件回调命名
  • 组件化优于多层 render
  • 状态上移优于公共方法
  • 容器组件
  • 纯函数的 render
  • 始终声明 PropTypes
  • Props 非空检测
  • 使用 Props 初始化
  • classnames

· One min read
<!-- bitdata -->
<script src="https://cdn.ravenjs.com/3.26.4/raven.min.js" crossorigin="anonymous"></script>
<script>
Raven.config('https://dd21f2cdb6e5465fa93b57b7e8522735@sentry.io/1280151').install()
</script>

· One min read
touch .babelrc

npm install --save-dev babel-preset-es2015

babel statics/backend-im/js/main.js > statics/backend-im/js/main.min.js

{
"presets": ["es2015"]
}

· One min read

install

npm install -g cnpm --registry=https://registry.npm.taobao.org
alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"

cnpm install -g electron-packager

electron-packager . echo-test --platform=win32 --arch=x64 --icon=./app/assets/images/tx.jpg --overwrite --out ./dist --version=1.1.0

· One min read
#官方编译过的二进制数据包安装
wget https://nodejs.org/download/release/latest-v12.x/node-v12.13.1-linux-x64.tar.gz
tar --strip-components 1 -xzvf node-v* -C /usr

proxy

#npm config set registry http://registry.npm.taobao.org --global
#npm config set disturl http://npm.taobao.org/dist --global
npm config set registry http://registry.npmmirror.com
npm install -g yarn
yarn config set "strict-ssl" false -g
yarn

node 升级

npm install -g n
n stable

yum erase nodejs npm -y # 卸载旧版本的nodejs
rpm -qa 'node|npm' | grep -v nodesource # 确认nodejs是否卸载干净

npx

npx webpack === ./node_modules/.bin/webpack

publish

npm loging
npm publish --access public

yarn

# dependencies
yarn add @wolanx/react-netron
# devDependencies
yarn add -D rollup
# delete
yarn remove @wolanx/react-netron

yarn link # lib path
yarn link @wolanx/react-netron # proj path
yarn unlink @wolanx/react-netron # proj path

yarn upgrade @tauri-apps/cli @tauri-apps/api --latest
yarn upgrade-interactive --latest

esbuild

npm install --save-exact esbuild

esbuild src/test.js --bundle --outfile=dist/test.js

· One min read

download data

download('aaa', '1.txt', 'text/plain');

function download(text, name, type) {
var file = new Blob([text], {
type: type
})
var a = $('<a id="download-it">Download it</a>').appendTo('body')
a[0].href = URL.createObjectURL(file)
a[0].download = name
a[0].click()
}

是否当前窗口

var vis = (function () {
var stateKey, eventKey, keys = {
hidden: "visibilitychange",
webkitHidden: "webkitvisibilitychange",
mozHidden: "mozvisibilitychange",
msHidden: "msvisibilitychange"
};
for (stateKey in keys) {
if (stateKey in document) {
eventKey = keys[stateKey];
break;
}
}
return function (c) {
if (c) document.addEventListener(eventKey, c);
return !document[stateKey];
}
})();

· One min read
gulpfile.js
var gulp = require('gulp')
var watch = require('gulp-watch');
var component = require('gulp-component');

gulp.task('default', function () {
// 观察 *.js 并配置 component.json scripts
return watch(['component.json', 'src/**/*.js'], function (v) {
console.log(v.path);
gulp.src('component.json')
.pipe(component.scripts({
standalone: true,
}))
.pipe(gulp.dest('./dist'));
})
});
component.json
{
"name": "Zhaoyujie",
"version": "0.10.5",
"main": "src/test.js",
"author": "Evan You <yyx990803@gmail.com>",
"description": "Simple, Fast & Composable MVVM for building interative interfaces",
"keywords": [
"mvvm",
"framework",
"data binding"
],
"license": "MIT",
"scripts": [
"src/main.js",
"src/emitter.js",
"src/config.js",
"src/utils.js",
"src/fragment.js",
"src/compiler.js",
"src/viewmodel.js",
"src/binding.js",
"src/observer.js",
"src/directive.js",
"src/exp-parser.js",
"src/text-parser.js",
"src/deps-parser.js",
"src/filters.js",
"src/transition.js",
"src/batcher.js",
"src/directives/index.js",
"src/directives/if.js",
"src/directives/repeat.js",
"src/directives/on.js",
"src/directives/model.js",
"src/directives/with.js",
"src/directives/html.js",
"src/directives/style.js",
"src/directives/partial.js",
"src/directives/view.js",
"src/test.js",
"src/a.js",
"src/b.js"
]
}