From 28e2952d8d4953b641ce4ccd47c0edcc642147f1 Mon Sep 17 00:00:00 2001 From: Vendeville Antoine Date: Wed, 17 Aug 2022 10:28:54 +0200 Subject: [PATCH] build(@vtmn/svelte): fix build --- packages/sources/svelte/package.json | 15 +++++++----- packages/sources/svelte/rollup.config.js | 29 +++++++++++++++++++++--- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/sources/svelte/package.json b/packages/sources/svelte/package.json index 57b5f5869..7031e21d1 100644 --- a/packages/sources/svelte/package.json +++ b/packages/sources/svelte/package.json @@ -31,10 +31,7 @@ "test": "jest src", "test:watch": "npm run test -- --watch" }, - "devDependencies": { - "@rollup/plugin-node-resolve": "^13.1.2", - "@testing-library/jest-dom": "^5.16.2", - "@testing-library/svelte": "^3.0.3", + "dependencies": { "@vtmn/css-accordion": "^0.5.0", "@vtmn/css-alert": "^0.8.3", "@vtmn/css-badge": "^0.13.0", @@ -67,7 +64,12 @@ "@vtmn/css-toast": "^0.7.2", "@vtmn/css-toggle": "^0.8.2", "@vtmn/css-tooltip": "^0.8.2", - "@vtmn/icons": "^0.14.0", + "@vtmn/icons": "^0.14.0" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^13.1.2", + "@testing-library/jest-dom": "^5.16.2", + "@testing-library/svelte": "^3.0.3", "babel-jest": "^28.1.0", "chokidar-cli": "^3.0.0", "eslint": "8.18.0", @@ -82,7 +84,8 @@ "rollup-plugin-svelte": "^7.1.0", "svelte": "3.49.0", "svelte-jester": "^2.3.2", - "svelte-preprocess": "4.10.7" + "svelte-preprocess": "4.10.7", + "rollup-plugin-terser": "^7.0.2" }, "jest": { "testEnvironment": "jsdom", diff --git a/packages/sources/svelte/rollup.config.js b/packages/sources/svelte/rollup.config.js index 3efbdfd96..706c38192 100644 --- a/packages/sources/svelte/rollup.config.js +++ b/packages/sources/svelte/rollup.config.js @@ -6,6 +6,8 @@ import postcssImport from 'postcss-import'; import postcssUrl from 'postcss-url'; import fs from 'fs'; import path from 'path'; +import pkg from './package.json'; +import { terser } from 'rollup-plugin-terser'; const preprocessOptions = require('./svelte.config').preprocessOptions; @@ -40,17 +42,38 @@ const postcssProcess = (component, variant = '') => ], }); +const globals = { + 'svelte/internal': 'svelte/internal', + svelte: 'svelte', +}; + const svelteOptions = (component, variant) => ({ + external: /^svelte.*$/, output: [ - { file: `dist/index.mjs`, format: 'es' }, - { file: `dist/index.js`, format: 'umd', name: 'index' }, + { + file: pkg.module, + format: 'es', + sourcemap: true, + globals, + }, + { + file: pkg.main, + format: 'umd', + name: 'index', + sourcemap: true, + globals, + }, ], plugins: [ svelte({ preprocess: sveltePreprocess(preprocessOptions), }), postcssProcess(component, variant), - resolve(), + resolve({ + // Exclude all svelte related stuff + resolveOnly: [/^(?!svelte.*$)/], + }), + terser(), ], });