|
1 | 1 | import { defineConfig } from 'vite';
|
2 | 2 | import vue from '@vitejs/plugin-vue';
|
| 3 | +import license from 'rollup-plugin-license'; |
3 | 4 |
|
4 | 5 | const path = require('path');
|
| 6 | +const minify = process.argv.includes('--minify'); |
| 7 | + |
| 8 | +// Change build process based on whether we're building a minified version. |
| 9 | +const libConfig = { |
| 10 | + minified: { |
| 11 | + formats: ['es'], |
| 12 | + entry: path.resolve(__dirname, 'src/main.ts'), |
| 13 | + name: 'imgix-vue', |
| 14 | + fileName: () => 'imgix-vue.min.js', |
| 15 | + }, |
| 16 | + default: { |
| 17 | + formats: ['es', 'umd'], |
| 18 | + entry: path.resolve(__dirname, 'src/main.ts'), |
| 19 | + name: 'imgix-vue', |
| 20 | + fileName: (format) => { |
| 21 | + if (format === 'es') { |
| 22 | + return `imgix-vue.esm.js`; |
| 23 | + } |
| 24 | + return `imgix-vue.${format}.js`; |
| 25 | + }, |
| 26 | + }, |
| 27 | +}; |
| 28 | + |
| 29 | +const config = minify ? libConfig.minified : libConfig.default; |
| 30 | + |
5 | 31 | export default defineConfig({
|
6 | 32 | plugins: [vue()],
|
| 33 | + esbuild: { |
| 34 | + legalComments: 'none', // Preserve all legal comments. |
| 35 | + banner: '/*! licenses: /vendor.LICENSE.txt */', |
| 36 | + }, |
| 37 | + build: { |
| 38 | + // Don't delete the outDir between builds. |
| 39 | + // NPM script deletes outDir before building. |
| 40 | + emptyOutDir: false, |
| 41 | + minify: minify, |
| 42 | + target: 'es2018', |
| 43 | + lib: { |
| 44 | + ...config, |
| 45 | + }, |
| 46 | + rollupOptions: { |
| 47 | + external: ['vue'], |
| 48 | + output: { |
| 49 | + // esbuild strips comments, so we need to add a banner to the output in |
| 50 | + // order to preserve the licenses. |
| 51 | + plugins: [ |
| 52 | + license({ |
| 53 | + thirdParty: { |
| 54 | + output: path.resolve(__dirname, './dist/vendor.LICENSE.txt'), |
| 55 | + }, |
| 56 | + }), |
| 57 | + ], |
| 58 | + globals: { |
| 59 | + vue: 'Vue', |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
7 | 64 | resolve: {
|
8 | 65 | alias: {
|
9 | 66 | '@': path.resolve(__dirname, './src'),
|
|
0 commit comments