From ea836a1fb5cb7529a5c170dcdaecc2343156bbf3 Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Wed, 14 Sep 2022 13:15:04 +0200 Subject: [PATCH] chore: improve vite config in ts-example (#104) bump vite from 2.9.12 to 3.1.0 add vite config to generate a dedicated chunk for maxgraph@core. It lets know the size the produced bundle in an external application and if tree shaking works. --- packages/ts-example/README.md | 2 +- packages/ts-example/package.json | 2 +- packages/ts-example/vite.config.js | 33 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 packages/ts-example/vite.config.js diff --git a/packages/ts-example/README.md b/packages/ts-example/README.md index a03765878..dcbdb3fbf 100644 --- a/packages/ts-example/README.md +++ b/packages/ts-example/README.md @@ -5,7 +5,7 @@ Initialized from https://github.com/vitejs/vite/tree/v2.9.8/packages/create-vite Do not forget to initialize all packages (you may also need to build the maxgraph@core package) > From the repository root, run `npm install`. -Run `npm run dev` and go to http://localhost:3000/ +Run `npm run dev` and go to http://localhost:5173/ If you want to bundle the application, run `npm run build` and then run `npm run preview` to access to a preview of the bundle application. diff --git a/packages/ts-example/package.json b/packages/ts-example/package.json index 16555a78f..907efbf7c 100644 --- a/packages/ts-example/package.json +++ b/packages/ts-example/package.json @@ -12,6 +12,6 @@ "@maxgraph/core": "*" }, "devDependencies": { - "vite": "~2.9.12" + "vite": "~3.1.0" } } diff --git a/packages/ts-example/vite.config.js b/packages/ts-example/vite.config.js new file mode 100644 index 000000000..3862fb640 --- /dev/null +++ b/packages/ts-example/vite.config.js @@ -0,0 +1,33 @@ +/* +Copyright 2022-present The maxGraph project Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { defineConfig } from 'vite'; + +export default defineConfig(({ mode }) => { + return { + build: { + rollupOptions: { + output: { + manualChunks: { + // put the maxgraph code in a dedicated file. It lets know the size the produced bundle in an external application and if tree shaking works + maxgraph: ['@maxgraph/core'], + }, + }, + }, + // chunkSizeWarningLimit: 553, // maxgraph + }, + }; +});