From 7d9e364b15c15d708b50fe6893005215157e686e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= Date: Thu, 1 Apr 2021 10:30:24 +0800 Subject: [PATCH] feat: utils.buildins() --- package.json | 1 - script/rollup.config.ts | 8 +++++--- script/utils.ts | 4 ++++ vite.config.ts | 19 ++++++++++--------- yarn.lock | 36 +----------------------------------- 5 files changed, 20 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index c2b3e61..08830b2 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "ora": "^5.4.0", "rimraf": "^3.0.2", "rollup-plugin-esbuild": "^3.0.2", - "rollup-plugin-node-externals": "^2.2.0", "ts-node": "^9.1.1", "typescript": "^4.2.3", "vite": "^2.1.3" diff --git a/script/rollup.config.ts b/script/rollup.config.ts index 05d72db..bdefc0a 100644 --- a/script/rollup.config.ts +++ b/script/rollup.config.ts @@ -5,7 +5,7 @@ import commonjs from '@rollup/plugin-commonjs' import esbuild from 'rollup-plugin-esbuild' import alias from '@rollup/plugin-alias' import json from '@rollup/plugin-json' -import externals from 'rollup-plugin-node-externals' +import { builtins } from './utils' export default (env = 'production') => { const options: RollupOptions = { @@ -49,9 +49,11 @@ export default (env = 'production') => { { find: '@main', replacement: join(__dirname, '../src/main'), }, ] }), - externals(), ], - external: ['electron'], + external: [ + ...builtins(), + 'electron', + ], } return options diff --git a/script/utils.ts b/script/utils.ts index 4ac0438..67b4f86 100644 --- a/script/utils.ts +++ b/script/utils.ts @@ -1,3 +1,4 @@ +import { builtinModules } from 'module' import { sep } from 'path' import { get } from 'http' import { green } from 'chalk' @@ -39,3 +40,6 @@ export function cjs2esm() { }, } } + +/** node.js 内置模块 */ +export const builtins = () => builtinModules.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x)) diff --git a/vite.config.ts b/vite.config.ts index 863d149..8d1820b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,9 +2,8 @@ require('dotenv').config({ path: join(__dirname, '.env') }) import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' -import externals from 'rollup-plugin-node-externals' import { join } from 'path' -import { cjs2esm } from './script/utils' +import { builtins } from './script/utils' // https://vitejs.dev/config/ export default defineConfig({ @@ -20,17 +19,19 @@ export default defineConfig({ '@root': __dirname, }, }, - optimizeDeps: { - exclude: ['electron-store', 'electron'] - }, build: { outDir: join(__dirname, 'dist/render'), + emptyOutDir: true, + minify: false, + commonjsOptions: {}, rollupOptions: { - external: ['electron'], - plugins: [ - externals(), - // cjs2esm(), + external: [ + ...builtins(), + 'electron', ], + output: { + format: 'cjs', + }, }, }, }) diff --git a/yarn.lock b/yarn.lock index 596f06e..a88624b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1254,14 +1254,6 @@ find-up@^3.0.0: dependencies: locate-path "^3.0.0" -find-up@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" - integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== - dependencies: - locate-path "^5.0.0" - path-exists "^4.0.0" - fs-extra@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" @@ -1771,13 +1763,6 @@ locate-path@^3.0.0: p-locate "^3.0.0" path-exists "^3.0.0" -locate-path@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" - integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g== - dependencies: - p-locate "^4.1.0" - lodash.camelcase@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" @@ -1989,7 +1974,7 @@ p-cancelable@^1.0.0: resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.1.0.tgz#d078d15a3af409220c886f1d9a0ca2e441ab26cc" integrity sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw== -p-limit@^2.0.0, p-limit@^2.2.0: +p-limit@^2.0.0: version "2.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== @@ -2003,13 +1988,6 @@ p-locate@^3.0.0: dependencies: p-limit "^2.0.0" -p-locate@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" - integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== - dependencies: - p-limit "^2.2.0" - p-try@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" @@ -2040,11 +2018,6 @@ path-exists@^3.0.0: resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" integrity sha1-zg6+ql94yxiSXqfYENe1mwEP1RU= -path-exists@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" - integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== - path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -2350,13 +2323,6 @@ rollup-plugin-esbuild@^3.0.2: joycon "^3.0.0" jsonc-parser "^3.0.0" -rollup-plugin-node-externals@^2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-node-externals/-/rollup-plugin-node-externals-2.2.0.tgz#23946e8c0fdd0e321cc3f225d4cebc3d819d17c4" - integrity sha512-WM7TtQ76GdsLceEGmZzQzn1afj8JgOQT5VLs1Y9RMqowM/8eK2mBj/Lv7hoE833U75QsUZIRirYUtFatu51RJA== - dependencies: - find-up "^4.1.0" - rollup@^2.38.5: version "2.39.0" resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.39.0.tgz#be4f98c9e421793a8fec82c854fb567c35e22ab6"