-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit afe0932
Showing
18 changed files
with
4,831 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { UserConfig } from '@commitlint/types' | ||
|
||
const Configuration: UserConfig = { | ||
extends: ['@commitlint/config-conventional'], | ||
} | ||
|
||
export default Configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | ||
|
||
name: Node.js Package | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
|
||
jobs: | ||
test-build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: pnpm/action-setup@v4 | ||
name: Install pnpm | ||
with: | ||
version: 9 | ||
run_install: false | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org/ | ||
cache: 'pnpm' | ||
|
||
- run: pnpm install | ||
- run: pnpm run test | ||
- run: pnpm run build | ||
- run: cd dist && npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
.idea | ||
|
||
.DS_Store | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx --no -- commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
node_modules | ||
dist | ||
public | ||
tsconfig.json | ||
.commitlintrc.ts | ||
.prettierrc.js | ||
yarn.lock | ||
package.lock | ||
.idea | ||
pnpm-lock.yaml | ||
enpm-lock.yaml | ||
auto-imports.d.ts | ||
components.d.ts | ||
.local | ||
/node_modules/** | ||
|
||
**/*.svg | ||
**/*.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
printWidth: 80, // 单行长度,超过则自动换行 | ||
tabWidth: 2, // 缩进长度 | ||
useTabs: false, // 使用空格代替tab缩进 | ||
semi: false, // 句末使用分号 | ||
singleQuote: true, // 使用单引号 | ||
endOfLine: 'auto', // 配置换行符格式为auto | ||
arrowParens: 'avoid', // 箭头函数仅有一个参数时,参数是否加括号 | ||
bracketSpacing: true, // 在对象花括号内侧使用空格作为间隔 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 mingtianyihou33 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# vite-plugin-replace-lodash | ||
|
||
**English** | [中文](./README.zh_CN.md) | ||
|
||
A `Vite` plugin is used to replace `lodash` with `lodash-es` to prevent all lodash modules are imported and the bundle volume is too large because it cannot tree-shaking. | ||
Note: The 'lodash-es' module needs to be installed separately. | ||
|
||
## Install | ||
|
||
npm: | ||
|
||
```bash | ||
npm install vite-plugin-replace-lodash | ||
``` | ||
|
||
pnpm: | ||
|
||
```bash | ||
pnpm add vite-plugin-replace-lodash | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { defineConfig } from 'vite'; | ||
import { replaceLodash } from 'vite-plugin-replace-lodash'; | ||
|
||
export default defineConfig({ | ||
plugins: [replaceLodash()], | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# vite-plugin-replace-lodash | ||
|
||
**中文** | [English](./README.md) | ||
|
||
用于替换 `lodash` 为 `lodash-es` 的 `Vite` 插件,避免lodash模块被全部引入,无法 tree-shaking,造成的bundle体积过大。 | ||
注意:需要单独安装 `lodash-es` 模块 | ||
|
||
## 安装 | ||
|
||
npm: | ||
|
||
```bash | ||
npm install vite-plugin-replace-lodash | ||
``` | ||
|
||
pnpm: | ||
|
||
```bash | ||
pnpm add vite-plugin-replace-lodash | ||
``` | ||
|
||
## 使用 | ||
```typescript | ||
import { defineConfig } from 'vite'; | ||
import { replaceLodash } from 'vite-plugin-replace-lodash'; | ||
|
||
export default defineConfig({ | ||
plugins: [replaceLodash()], | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { replaceLodash } from '../src/index.js' | ||
import { describe, test, expect } from 'vitest' | ||
|
||
describe('replace lodash plugin', () => { | ||
const { name, transform: _transform } = replaceLodash() | ||
let transform = _transform as ( | ||
code: string, | ||
id: string, | ||
) => null | { code: string; map?: string } | ||
test('Is correct name?', async () => { | ||
expect(name).toEqual('vite:replace-lodash') | ||
}) | ||
test('When filename is svg', async () => { | ||
expect(transform('', 'a.svg')).toEqual(null) | ||
}) | ||
test('import lodash use single quote', async () => { | ||
const code = `import { isArray } from 'lodash'` | ||
expect(transform(code, 'test.js')!.code).toEqual( | ||
`import { isArray } from 'lodash-es'`, | ||
) | ||
}) | ||
|
||
test('import lodash use double quote', async () => { | ||
const code = `import { isArray } from "lodash"` | ||
expect(transform(code, 'test.js')!.code).toEqual( | ||
`import { isArray } from "lodash-es"`, | ||
) | ||
}) | ||
test('multiple line import lodash', async () => { | ||
const code = `import { isArray } from 'lodash' | ||
import { debounce } from "lodash"` | ||
expect(transform(code, 'test.js')!.code) | ||
.toEqual(`import { isArray } from 'lodash-es' | ||
import { debounce } from "lodash-es"`) | ||
}) | ||
test('import lodash full', async () => { | ||
const code = `import lodash from 'lodash' | ||
lodash.isArray([])` | ||
expect(transform(code, 'test.js')!.code) | ||
.toEqual(`import lodash from 'lodash-es' | ||
lodash.isArray([])`) | ||
}) | ||
test('import lodash/debounce', async () => { | ||
const code = `import debounce from "lodash/debounce"` | ||
expect(transform(code, 'test.js')!.code).toEqual(code) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
clean: true, | ||
entries: ['./src/index'], | ||
declaration: true, | ||
rollup: { | ||
emitCJS: true, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "vite-plugin-replace-lodash", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"author": "mingtianyihou33 <[email protected]>", | ||
"repository": "https://github.com/mingtianyihou33/vite-plugin-replace-lodash.git", | ||
"license": "MIT", | ||
"type": "module", | ||
"scripts": { | ||
"version": "node scripts/version.js && npm run changelog", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", | ||
"build": "unbuild && node scripts/genPkgInfo.js", | ||
"prettier": "prettier --write .", | ||
"prepare": "husky", | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^19.5.0", | ||
"@commitlint/config-conventional": "^19.5.0", | ||
"@commitlint/types": "^19.5.0", | ||
"conventional-changelog-cli": "^5.0.0", | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.7", | ||
"prettier": "^3.3.3", | ||
"typescript": "^5.6.3", | ||
"unbuild": "^2.0.0", | ||
"vitest": "^2.1.5" | ||
}, | ||
"peerDependencies": { | ||
"vite": "^5.4.11" | ||
}, | ||
"lint-staged": { | ||
"*.{js?(x),ts?(x),vue}": [ | ||
"prettier --write" | ||
] | ||
} | ||
} |
Oops, something went wrong.