diff --git a/package.json b/package.json index 427f6fc..928a68b 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@babel/core": "^7.21.8", "@babel/preset-env": "^7.21.5", "@rollup/plugin-babel": "^6.0.3", + "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-node-resolve": "^15.0.2", "@rollup/plugin-terser": "^0.4.1", "@rollup/plugin-typescript": "^11.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 707d8cd..a26d2b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,6 +45,9 @@ devDependencies: '@rollup/plugin-babel': specifier: ^6.0.3 version: 6.0.3(@babel/core@7.21.8)(@types/babel__core@7.20.0)(rollup@3.21.6) + '@rollup/plugin-commonjs': + specifier: ^25.0.0 + version: 25.0.0(rollup@3.21.6) '@rollup/plugin-node-resolve': specifier: ^15.0.2 version: 15.0.2(rollup@3.21.6) @@ -1696,6 +1699,24 @@ packages: rollup: 3.21.6 dev: true + /@rollup/plugin-commonjs@25.0.0(rollup@3.21.6): + resolution: {integrity: sha512-hoho2Kay9TZrLu0bnDsTTCaj4Npa+THk9snajP/XDNb9a9mmjTjh52EQM9sKl3HD1LsnihX7js+eA2sd2uKAhw==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.68.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.2(rollup@3.21.6) + commondir: 1.0.1 + estree-walker: 2.0.2 + glob: 8.1.0 + is-reference: 1.2.1 + magic-string: 0.27.0 + rollup: 3.21.6 + dev: true + /@rollup/plugin-node-resolve@15.0.2(rollup@3.21.6): resolution: {integrity: sha512-Y35fRGUjC3FaurG722uhUuG8YHOJRJQbI6/CkbRkdPotSpDj9NtIN85z1zrcyDcCQIW4qp5mgG72U+gJ0TAFEg==} engines: {node: '>=14.0.0'} @@ -2504,6 +2525,10 @@ packages: engines: {node: '>= 6'} dev: true + /commondir@1.0.1: + resolution: {integrity: sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==} + dev: true + /compressing@1.9.0: resolution: {integrity: sha512-WBNRH/mIV7aEFuYQFk4zCQZPEXDtyuCCeIcq5wYbmk5VewmUWV1YXAGyG6+hwrRGfG3HTy3c4BV79yfgloPJWQ==} engines: {node: '>= 4.0.0'} @@ -3265,6 +3290,12 @@ packages: engines: {node: '>=0.10.0'} dev: false + /is-reference@1.2.1: + resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==} + dependencies: + '@types/estree': 1.0.1 + dev: true + /is-relative@1.0.0: resolution: {integrity: sha512-Kw/ReK0iqwKeu0MITLFuj0jbPAmEiOsIwyIXvvbfa6QfmN9pkD1M+8pdk7Rl/dTKbH34/XBFMbgD4iMJhLQbGA==} engines: {node: '>=0.10.0'} diff --git a/script/build.ts b/script/build.ts index 53f908a..8885573 100644 --- a/script/build.ts +++ b/script/build.ts @@ -7,6 +7,8 @@ import * as rollup from 'rollup'; import typescript from '@rollup/plugin-typescript'; import rollupBabel from '@rollup/plugin-babel'; import terser from '@rollup/plugin-terser'; +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; (async function () { const timestamp = Date.now(); @@ -128,7 +130,9 @@ import terser from '@rollup/plugin-terser'; babelHelpers: 'bundled', sourceType: 'module' }), - terser() + terser(), + resolve(), + commonjs() ] }); await build.write({ diff --git a/script/dev.ts b/script/dev.ts index da68a06..94f9cfa 100644 --- a/script/dev.ts +++ b/script/dev.ts @@ -15,6 +15,7 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import EventEmitter from 'events'; import { WebSocket, WebSocketServer } from 'ws'; import chokidar from 'chokidar'; +import commonjs from '@rollup/plugin-commonjs'; const base = './public'; @@ -144,10 +145,13 @@ async function getEsmFile( }, cache: true, watch: { - exclude: '**/node_modules/**', - buildDelay: 200 + exclude: '**/node_modules/**' }, - plugins: [typescript({ sourceMap: true }), nodeResolve()], + plugins: [ + typescript({ sourceMap: true }), + nodeResolve(), + commonjs() + ], onwarn() {} }); @@ -479,7 +483,8 @@ function watchProject() { '**/_save/**', /\.min\./, /(^|[\/\\])\../, - /(^|[\/\\])[^a-zA-Z:\._0-9\/\\]/ + /(^|[\/\\])[^a-zA-Z:\._0-9\/\\]/, + /_.*/ ] }); watcher.on('change', async path => { @@ -514,9 +519,7 @@ function watchProject() { } // 剩余内容全部reload - if (!/_.*/.test(path)) { - ws.send(JSON.stringify({ type: 'reload' })); - } + ws.send(JSON.stringify({ type: 'reload' })); }); }