├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .github └── workflows │ ├── checks.yml │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── README.md ├── package.json ├── pnpm-lock.yaml ├── renovate.json ├── src └── index.ts ├── tsconfig.build.json ├── tsconfig.json └── tsconfig.lint.json /.eslintignore: -------------------------------------------------------------------------------- 1 | /dist/ 2 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: ['@djaler/typescript'], 4 | parserOptions: { 5 | project: './tsconfig.lint.json', 6 | }, 7 | settings: { 8 | 'import/resolver': { 9 | typescript: {}, 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ts text eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/checks.yml: -------------------------------------------------------------------------------- 1 | name: Checks 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Check out Git repository 15 | uses: actions/checkout@v2 16 | - name: Set up Node.js 17 | uses: actions/setup-node@v2 18 | with: 19 | node-version: 12 20 | - name: Cache pnpm modules 21 | uses: actions/cache@v2 22 | env: 23 | cache-name: cache-pnpm-modules 24 | with: 25 | path: ~/.pnpm-store 26 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }} 27 | restore-keys: | 28 | ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}- 29 | - name: Install dependencies 30 | uses: pnpm/action-setup@v2.0.0 31 | with: 32 | version: 5 33 | run_install: true 34 | - name: Run build 35 | run: npm run build 36 | 37 | lint: 38 | runs-on: ubuntu-latest 39 | 40 | steps: 41 | - name: Check out Git repository 42 | uses: actions/checkout@v2 43 | - name: Set up Node.js 44 | uses: actions/setup-node@v2 45 | with: 46 | node-version: 12 47 | - name: Cache pnpm modules 48 | uses: actions/cache@v2 49 | env: 50 | cache-name: cache-pnpm-modules 51 | with: 52 | path: ~/.pnpm-store 53 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }} 54 | restore-keys: | 55 | ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}- 56 | - name: Install dependencies 57 | uses: pnpm/action-setup@v2.0.0 58 | with: 59 | version: 5 60 | run_install: true 61 | - name: Run linter 62 | uses: reviewdog/action-eslint@v1 63 | with: 64 | reporter: github-check 65 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Check out Git repository 14 | uses: actions/checkout@v2 15 | with: 16 | fetch-depth: 0 17 | - name: Set up Node.js 18 | uses: actions/setup-node@v2 19 | with: 20 | node-version: 12 21 | - name: Cache pnpm modules 22 | uses: actions/cache@v2 23 | env: 24 | cache-name: cache-pnpm-modules 25 | with: 26 | path: ~/.pnpm-store 27 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }} 28 | restore-keys: | 29 | ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}- 30 | - name: Install dependencies 31 | uses: pnpm/action-setup@v2.0.0 32 | with: 33 | version: 5 34 | run_install: true 35 | - uses: filipstefansson/set-npm-token-action@v1 36 | with: 37 | token: ${{ secrets.NPM_TOKEN }} 38 | - name: Publish package 39 | run: npm run publish 40 | - name: Create github release 41 | run: npm run release:github 42 | env: 43 | CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }} 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ 3 | .idea/ 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## [0.0.4](https://github.com/Djaler/vue-cli-plugin-esbuild/compare/v0.0.3...v0.0.4) (2021-03-26) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * correctly get packages version to generate cache config ([f2574c4](https://github.com/Djaler/vue-cli-plugin-esbuild/commit/f2574c4eb90f2467cd52c1f2d598dd3c486759c2)) 11 | 12 | 13 | 14 | ## [0.0.3](https://github.com/Djaler/vue-cli-plugin-esbuild/compare/v0.0.2...v0.0.3) (2021-03-25) 15 | 16 | 17 | ### Dependencies 18 | 19 | * update dependency esbuild-loader to 2.10.0 ([ec7a5e4](https://github.com/Djaler/vue-cli-plugin-esbuild/commit/ec7a5e4c510ddcbb9544396744a85509d739ef12)) 20 | 21 | 22 | 23 | ### [0.0.2](https://github.com/Djaler/vue-cli-plugin-esbuild/compare/v0.0.1...v0.0.2) (2021-03-07) 24 | 25 | 26 | ### Bug Fixes 27 | 28 | * create js rule if it not exist ([5c49caf](https://github.com/Djaler/vue-cli-plugin-esbuild/commit/5c49caf55e0e4f45d9211333537ba44a8cc7c67b)) 29 | 30 | ### 0.0.1 (2021-03-05) 31 | 32 | 33 | ### Features 34 | 35 | * initial ([42c07b7](https://github.com/Djaler/vue-cli-plugin-esbuild/commit/42c07b747c3e9ef94ea29bc2702105aed6db21d1)) 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm](https://img.shields.io/npm/v/vue-cli-plugin-esbuild?style=for-the-badge)](https://www.npmjs.com/package/vue-cli-plugin-esbuild) 2 | 3 | # vue-cli-plugin-esbuild 4 | 5 | > Vue CLI plugin to use [esbuild](https://esbuild.github.io/) for js/ts compilation and minification 6 | 7 | ## 🚀 Install 8 | 9 | ```sh 10 | vue add esbuild 11 | ``` 12 | or 13 | ```sh 14 | npm install --save-dev vue-cli-plugin-esbuild 15 | ``` 16 | 17 | ## 💪 Contributing 18 | 19 | Bug reports and pull requests are welcome on GitHub at https://github.com/djaler/vue-cli-plugin-esbuild. 20 | 21 | ## ©️ License 22 | 23 | The package is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-cli-plugin-esbuild", 3 | "version": "0.0.4", 4 | "author": "Kirill Romanov", 5 | "license": "MIT", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/Djaler/vue-cli-plugin-esbuild" 9 | }, 10 | "keywords": [ 11 | "vue", 12 | "cli", 13 | "esbuild" 14 | ], 15 | "scripts": { 16 | "preinstall": "npx only-allow pnpm", 17 | "lint": "eslint .", 18 | "lint:fix": "npm run lint -- --fix", 19 | "build": "tsc -p tsconfig.build.json", 20 | "prerelease": "npm run lint && npm run build", 21 | "release": "standard-version --preset @djaler/standard", 22 | "release:github": "conventional-github-releaser -p @djaler/standard", 23 | "publish": "npm run build && clean-publish" 24 | }, 25 | "files": [ 26 | "dist" 27 | ], 28 | "main": "./dist/index.js", 29 | "dependencies": { 30 | "browserslist": "^4.16.3", 31 | "esbuild-loader": "^2.10.0" 32 | }, 33 | "peerDependencies": { 34 | "@vue/cli-service": "^4.0.0-0", 35 | "webpack-chain": "^6.4.0" 36 | }, 37 | "devDependencies": { 38 | "@djaler/conventional-changelog-standard": "1.2.0", 39 | "@djaler/eslint-config-typescript": "0.0.5", 40 | "@vue/cli-service": "4.5.11", 41 | "clean-publish": "2.1.0", 42 | "conventional-github-releaser": "3.1.5", 43 | "eslint": "7.26.0", 44 | "eslint-import-resolver-typescript": "2.4.0", 45 | "husky": "4.3.8", 46 | "lint-staged": "10.5.4", 47 | "standard-version": "9.1.1", 48 | "typescript": "4.2.3", 49 | "webpack-chain": "6.5.1" 50 | }, 51 | "husky": { 52 | "hooks": { 53 | "pre-commit": "lint-staged" 54 | } 55 | }, 56 | "lint-staged": { 57 | "*.{js,ts}": "eslint --fix" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "github>djaler/renovate-config:js" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable global-require */ 2 | import { PluginAPI, ServicePlugin } from '@vue/cli-service'; 3 | import browserslist from 'browserslist'; 4 | import { ESBuildMinifyPlugin } from 'esbuild-loader'; 5 | import Config from 'webpack-chain'; 6 | 7 | const plugin: ServicePlugin = (api) => { 8 | api.chainWebpack((config) => { 9 | const target = browserslist() 10 | .map(value => value.replace(/\s/g, '')); 11 | 12 | const jsRule = config.module.rule('js').test(/\.m?jsx?$/); 13 | 14 | configureJs(jsRule, api, target); 15 | 16 | const tsRule = config.module.rules.get('ts'); 17 | 18 | if (tsRule) { 19 | configureTs(tsRule, api, target); 20 | } 21 | 22 | configureMinimizer(config, target); 23 | }); 24 | }; 25 | 26 | function configureJs(jsRule: Config.Rule, api: PluginAPI, target: string[]) { 27 | jsRule.uses 28 | .delete('thread-loader') 29 | .delete('babel-loader'); 30 | 31 | jsRule.use('cache-loader') 32 | .loader(require.resolve('cache-loader')) 33 | .options(api.genCacheConfig('js-esbuild-loader', { 34 | target, 35 | esbuildLoaderVersion: require('esbuild-loader/package.json').version, 36 | })); 37 | 38 | jsRule 39 | .use('esbuild-loader') 40 | .loader('esbuild-loader') 41 | .options({ 42 | target, 43 | }); 44 | } 45 | 46 | function configureTs(tsRule: Config.Rule, api: PluginAPI, target: string[]) { 47 | tsRule.uses 48 | .delete('thread-loader') 49 | .delete('babel-loader') 50 | .delete('ts-loader'); 51 | 52 | tsRule.use('cache-loader') 53 | .loader(require.resolve('cache-loader')) 54 | .options(api.genCacheConfig('ts-esbuild-loader', { 55 | target, 56 | esbuildLoaderVersion: require('esbuild-loader/package.json').version, 57 | // eslint-disable-next-line import/no-extraneous-dependencies 58 | typescriptVersion: require('typescript/package.json').version, 59 | }, 'tsconfig.json')); 60 | 61 | tsRule 62 | .use('esbuild-loader') 63 | .loader('esbuild-loader') 64 | .options({ 65 | target, 66 | loader: 'ts', 67 | }); 68 | } 69 | 70 | function configureMinimizer(config: Config, target: string[]) { 71 | (config.optimization as any).minimizers.delete('terser'); 72 | 73 | config.optimization.minimizer('esbuild-minify') 74 | .use(ESBuildMinifyPlugin, [{ 75 | target, 76 | }]); 77 | } 78 | 79 | export = plugin; 80 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "dist" 5 | }, 6 | "include": [ 7 | "src/**/*.ts" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "esModuleInterop": true 8 | }, 9 | "include": [ 10 | "src/**/*.ts" 11 | ], 12 | "exclude": [ 13 | "node_modules" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.lint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": [ 4 | ".eslintrc.js", 5 | "**/*.ts", 6 | ] 7 | } 8 | --------------------------------------------------------------------------------