Skip to content

Instantly share code, notes, and snippets.

View noyobo's full-sized avatar
💭
I may be slow to respond.

noyobo noyobo

💭
I may be slow to respond.
  • Tuya
  • Hangzhou China
View GitHub Profile
@noyobo
noyobo / WebpackFilesGraphPlugin.js
Last active November 7, 2023 08:05
Get webpack module dependencies
class MyPlugin {
apply(compiler) {
compiler.hooks.compilation.tap('MyPlugin', (compilation) => {
compilation.hooks.afterOptimizeDependencies.tap('MyPlugin', ( ) => {
const dependencyGraph = compilation.moduleGraph;
// 获取所有模块
const modules = compilation.modules;
// 构建模块映射表
const globby = require('globby');
const path = require('path');
const { detectiveModuleAndRequire } = require('detective-module');
const fse = require('fs-extra');
const isBuiltinModule = require('is-builtin-module');
const log = require('npmlog');
require('colors');
function unique(arr) {
return Array.from(new Set(arr));
let makeAllPackagesExternalPlugin = {
name: 'make-all-packages-external',
setup(build) {
let filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/ // Must not start with "/" or "./" or "../"
build.onResolve({ filter }, args => ({ path: args.path, external: true }))
},
}
@noyobo
noyobo / command.sh
Last active May 13, 2020 07:24
some commands
# 取消 dock 延时
defaults write com.apple.Dock autohide-delay -float 0 && killall Dock
defaults delete com.apple.Dock autohide-delay && killall Dock
# each run
for d in ./*/ ; do (cd "$d" && somecommand); done
# git remove merged branchs
alias gbdd="git branch --merged | grep -v '^* master$' | grep -v '^ master$' | xargs git branch -d"
const FETCH_TIMEOUT = 5000;
let didTimeOut = false;
new Promise(function(resolve, reject) {
const timeout = setTimeout(function() {
didTimeOut = true;
reject(new Error('Request timed out'));
}, FETCH_TIMEOUT);
fetch('https://davidwalsh.name/?xx1')
// 打开默认编辑器
const openEditor = (cwd, editor, basePath) => {
let editorPath = basePath;
if (editor === 'Sublime') {
if (isMac) {
editorPath = join(basePath, '/Contents/SharedSupport/bin/subl');
}
if (isWin) {
@noyobo
noyobo / git-m.sh
Last active March 24, 2017 14:15
Change the author and committer name and e-mail of multiple commits in Git
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL=$OLD_EMAIL
CORRECT_NAME=$GIT_NAME
CORRECT_EMAIL=$GIT_EMAIL
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
@noyobo
noyobo / decompress-tgz.js
Last active June 1, 2022 03:20
decompress tgz in nodejs
var fs = require('fs');
var zlib = require('zlib');
var path = require('path');
var tar = require('tar');
var mkdirp = require('mkdirp');
// 全解压
fs.createReadStream(path.resolve('./ice-2.0.50.tgz'))
.on('error', console.log)
.pipe(zlib.Unzip())
@noyobo
noyobo / gd.sh
Created July 23, 2016 13:43
check current git branch has diff
git diff --shortstat 2> /dev/null | tail -n1
@noyobo
noyobo / gist:875ac171083195198462d883e5acde37
Created June 4, 2016 17:46 — forked from JeffreyWay/gist:1525217
Instant Server for Current Directory
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'