From 2ba3ea57163835bd40ab32cd26407ad366a9763e Mon Sep 17 00:00:00 2001 From: Hung Viet Nguyen Date: Fri, 14 Oct 2022 11:46:14 +0700 Subject: [PATCH] feat: improve build process --- demo/package.json | 2 +- demo/vite.config.ts | 2 +- package.json | 10 ++-- pnpm-lock.yaml | 87 ++++++++++++++++++++++++++++++-- rollup.config.js | 16 ++++-- src/__tests__/less/index.test.ts | 2 +- tsconfig.prod.json | 2 +- 7 files changed, 105 insertions(+), 16 deletions(-) diff --git a/demo/package.json b/demo/package.json index f24ab91b..d4fcc0da 100644 --- a/demo/package.json +++ b/demo/package.json @@ -1,6 +1,6 @@ { "name": "demo", - "version": "0.3.1-alpha.0", + "version": "0.0.1", "private": true, "license": "MIT", "author": { diff --git a/demo/vite.config.ts b/demo/vite.config.ts index b10dbc35..722c5a71 100644 --- a/demo/vite.config.ts +++ b/demo/vite.config.ts @@ -19,7 +19,7 @@ export default defineConfig(({ mode }) => { {}, ); - // Inject NODE_ENV and make sure envWithProcessPrefix is not empty + // @ts-expect-error Inject NODE_ENV and make sure envWithProcessPrefix is not empty envWithProcessPrefix['process.env.NODE_ENV'] = `'${mode}'`; return { diff --git a/package.json b/package.json index 7e25a22f..eb62db61 100644 --- a/package.json +++ b/package.json @@ -80,11 +80,13 @@ "ws": "^8.5.0" }, "devDependencies": { - "@types/jest": "27", - "@jest/types": "27", "@babel/core": "^7.18.10", + "@jest/types": "27", + "@rollup/plugin-node-resolve": "^15.0.0", "@types/connect": "^3.4.35", + "@types/jest": "27", "@types/node": "^18.6.3", + "@types/react": "^17.0.48", "eslint": "^8.0.1", "eslint-config-prettier": "^8.5.0", "eslint-config-standard": "^17.0.0", @@ -96,9 +98,9 @@ "npm-run-all": "^4.1.5", "prettier": "^2.6.0", "react-is": "^18.2.0", - "rollup": "^2.77.2", + "rollup": "^2.79.1", "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-typescript2": "^0.31.2", + "rollup-plugin-typescript2": "^0.34.1", "typescript": "^4.6.3" }, "bug": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b76fea0a..03430e93 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,10 +6,12 @@ importers: specifiers: '@babel/core': ^7.18.10 '@jest/types': '27' + '@rollup/plugin-node-resolve': ^15.0.0 '@svgr/core': ^6.2.1 '@types/connect': ^3.4.35 '@types/jest': '27' '@types/node': ^18.6.3 + '@types/react': ^17.0.48 camelcase: ^6.3.0 chalk: ^4.1.2 chokidar: ^3.5.3 @@ -30,9 +32,9 @@ importers: postcss-load-config: ^4.0.1 prettier: ^2.6.0 react-is: ^18.2.0 - rollup: ^2.77.2 + rollup: ^2.79.1 rollup-plugin-terser: ^7.0.2 - rollup-plugin-typescript2: ^0.31.2 + rollup-plugin-typescript2: ^0.34.1 sirv: ^2.0.2 slash: ^3.0.0 string-hash: ^1.1.3 @@ -58,9 +60,11 @@ importers: devDependencies: '@babel/core': 7.18.10 '@jest/types': 27.5.1 + '@rollup/plugin-node-resolve': 15.0.0_rollup@2.79.1 '@types/connect': 3.4.35 '@types/jest': 27.5.2 '@types/node': 18.6.3 + '@types/react': 17.0.48 eslint: 8.23.1 eslint-config-prettier: 8.5.0_eslint@8.23.1 eslint-config-standard: 17.0.0_p6gl7hlfuayuj4pnyydm4qj6t4 @@ -72,9 +76,9 @@ importers: npm-run-all: 4.1.5 prettier: 2.7.1 react-is: 18.2.0 - rollup: 2.77.2 - rollup-plugin-terser: 7.0.2_rollup@2.77.2 - rollup-plugin-typescript2: 0.31.2_oo3i3f3qmqiztdz5qgxrrjmd5e + rollup: 2.79.1 + rollup-plugin-terser: 7.0.2_rollup@2.79.1 + rollup-plugin-typescript2: 0.34.1_5j6xs4al5kvj74qioxrurhiohm typescript: 4.7.4 demo: @@ -2824,6 +2828,24 @@ packages: resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==} dev: false + /@rollup/plugin-node-resolve/15.0.0_rollup@2.79.1: + resolution: {integrity: sha512-iwJbzfTzlzDDQcGmkS7EkCKwe2kSkdBrjX87Fy/KrNjr6UNnLpod0t6X66e502LRe5JJCA4FFqrEscWPnZAkig==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.78.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 4.2.1 + '@types/resolve': 1.20.2 + deepmerge: 4.2.2 + is-builtin-module: 3.2.0 + is-module: 1.0.0 + resolve: 1.22.1 + rollup: 2.79.1 + dev: true + /@rollup/pluginutils/4.2.1: resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} engines: {node: '>= 8.0.0'} @@ -3534,6 +3556,10 @@ packages: csstype: 3.1.0 dev: true + /@types/resolve/1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + dev: true + /@types/responselike/1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} dependencies: @@ -4431,6 +4457,11 @@ packages: ieee754: 1.2.1 dev: true + /builtin-modules/3.3.0: + resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} + engines: {node: '>=6'} + dev: true + /builtins/5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: @@ -7201,6 +7232,13 @@ packages: has-tostringtag: 1.0.0 dev: true + /is-builtin-module/3.2.0: + resolution: {integrity: sha512-phDA4oSGt7vl1n5tJvTWooWWAsXLY+2xCnxNqvKhGEzujg+A43wPlPOyDg3C8XQHN+6k/JTQWJ/j0dQh/qr+Hw==} + engines: {node: '>=6'} + dependencies: + builtin-modules: 3.3.0 + dev: true + /is-callable/1.2.4: resolution: {integrity: sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==} engines: {node: '>= 0.4'} @@ -7272,6 +7310,10 @@ packages: resolution: {integrity: sha512-z7CMFGNrENq5iFB9Bqo64Xk6Y9sg+epq1myIcdHaGnbMTYOxvzsEtdYqQUylB7LxfkvgrrjP32T6Ywciio9UIQ==} dev: true + /is-module/1.0.0: + resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} + dev: true + /is-negative-zero/2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} engines: {node: '>= 0.4'} @@ -10602,6 +10644,18 @@ packages: terser: 5.14.2 dev: true + /rollup-plugin-terser/7.0.2_rollup@2.79.1: + resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==} + peerDependencies: + rollup: ^2.0.0 + dependencies: + '@babel/code-frame': 7.18.6 + jest-worker: 26.6.2 + rollup: 2.79.1 + serialize-javascript: 4.0.0 + terser: 5.14.2 + dev: true + /rollup-plugin-typescript2/0.31.2_oo3i3f3qmqiztdz5qgxrrjmd5e: resolution: {integrity: sha512-hRwEYR1C8xDGVVMFJQdEVnNAeWRvpaY97g5mp3IeLnzhNXzSVq78Ye/BJ9PAaUfN4DXa/uDnqerifMOaMFY54Q==} peerDependencies: @@ -10618,6 +10672,21 @@ packages: typescript: 4.7.4 dev: true + /rollup-plugin-typescript2/0.34.1_5j6xs4al5kvj74qioxrurhiohm: + resolution: {integrity: sha512-P4cHLtGikESmqi1CA+tdMDUv8WbQV48mzPYt77TSTOPJpERyZ9TXdDgjSDix8Fkqce6soYz3+fa4lrC93IEkcw==} + peerDependencies: + rollup: '>=1.26.3' + typescript: '>=2.4.0' + dependencies: + '@rollup/pluginutils': 4.2.1 + find-cache-dir: 3.3.2 + fs-extra: 10.1.0 + rollup: 2.79.1 + semver: 7.3.7 + tslib: 2.4.0 + typescript: 4.7.4 + dev: true + /rollup/2.77.2: resolution: {integrity: sha512-m/4YzYgLcpMQbxX3NmAqDvwLATZzxt8bIegO78FZLl+lAgKJBd1DRAOeEiZcKOIOPjxE6ewHWHNgGEalFXuz1g==} engines: {node: '>=10.0.0'} @@ -10626,6 +10695,14 @@ packages: fsevents: 2.3.2 dev: true + /rollup/2.79.1: + resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==} + engines: {node: '>=10.0.0'} + hasBin: true + optionalDependencies: + fsevents: 2.3.2 + dev: true + /run-async/2.4.1: resolution: {integrity: sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==} engines: {node: '>=0.12.0'} diff --git a/rollup.config.js b/rollup.config.js index 712704c6..d11488a5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,15 +1,25 @@ import { defineConfig } from 'rollup'; import typescript from 'rollup-plugin-typescript2'; +import resolve from '@rollup/plugin-node-resolve'; +import packageJson from './package.json'; function makeBundle({ filePath, dir = 'dist' }) { return { input: filePath, output: { - dir: dir, + dir, format: 'cjs', }, - plugins: [typescript()], - external: ['path', 'camelcase', 'fs', 'child_process'], + plugins: [ + typescript({ + tsconfig: 'tsconfig.prod.json', + }), + resolve(), + ], + external: [ + ...Object.keys(packageJson.dependencies), + ...Object.keys(packageJson.devDependencies), + ], }; } diff --git a/src/__tests__/less/index.test.ts b/src/__tests__/less/index.test.ts index 1bdb85e0..5daaaf30 100644 --- a/src/__tests__/less/index.test.ts +++ b/src/__tests__/less/index.test.ts @@ -1,6 +1,6 @@ import path from 'path'; import { processLess } from '../../transform'; -import less from 'less'; + describe('Less', () => { it('should compile LESS successfully', () => { const result = processLess(path.resolve(__dirname, './style.less')); diff --git a/tsconfig.prod.json b/tsconfig.prod.json index b44de767..0e1ff0d7 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig", - "exclude": ["./demo/__tests__/**", "./demo/__mocks__/**", "./demo/test-utils"] + "exclude": ["./demo", "./src/__tests__/**"] }