-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
83 lines (79 loc) · 2.56 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { RollupBabelInputPluginOptions, babel } from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import copy, { CopyOptions } from 'rollup-plugin-copy';
import minifyHTML from 'rollup-plugin-minify-html-literals';
import summary from 'rollup-plugin-summary';
import { terser } from 'rollup-plugin-terser';
import { defineConfig } from 'vite';
import app from './package.json';
const babelConfig: RollupBabelInputPluginOptions = {
babelHelpers: 'bundled',
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
'@babel/plugin-proposal-export-default-from'
],
babelrc: false,
presets: [['@babel/preset-env', { targets: { chrome: '72' }, debug: true }]]
};
const copyConfig: CopyOptions = {
hook: 'closeBundle',
targets: [
{ src: 'node_modules/@webcomponents/webcomponentsjs/*', dest: 'dist/node_modules/@webcomponents/webcomponentsjs' },
{ src: 'public/index.universal.html', dest: 'dist', rename: 'index.html' },
{ src: 'res', dest: 'dist' }
]
};
// https://vitejs.dev/config/
export default (opts: { mode: 'production' | 'development'; command: 'build' | 'serve' }) => {
return defineConfig({
server: {
port: 8000
},
define: {
'process.env.NODE_ENV': JSON.stringify(opts.mode),
'process.env.VERSION': JSON.stringify(app.version)
},
plugins: [],
build: {
assetsInlineLimit: 100000,
rollupOptions: {
input: {
app: './src/lit-app.ts'
},
// input: ['src/my-element.ts'],
// Specifies two JS output configurations, modern and legacy, which the HTML plugin will
// automatically choose between; the legacy build is compiled to ES5
// and SystemJS modules
output: {
// Legacy JS bundles (ES5 compilation and SystemJS module output)
format: 'systemjs',
chunkFileNames: `${opts.mode == 'development' ? '[name].' : 'c.'}[hash].js`,
entryFileNames: '[name].bundle.js',
dir: 'dist'
},
plugins: [
// Minify HTML template literals
minifyHTML(),
babel(babelConfig),
// Resolve bare module specifiers to relative paths
resolve(),
// Copy res to dist folder
copy(copyConfig),
// Minify JS
terser({
format: {
comments: false
},
compress: false,
module: true
}),
// Print bundle summary
summary({}) as any
],
preserveEntrySignatures: false
}
}
});
};