2023-09-13 17:04:17 +00:00
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import react from '@vitejs/plugin-react';
|
2023-09-15 01:37:49 +00:00
|
|
|
import { defineConfig, type Plugin } from 'vite';
|
2023-09-13 17:04:17 +00:00
|
|
|
import compileTime from 'vite-plugin-compile-time';
|
|
|
|
import { createHtmlPlugin } from 'vite-plugin-html';
|
|
|
|
import vitePluginRequire from 'vite-plugin-require';
|
|
|
|
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
|
|
|
2023-09-15 01:37:49 +00:00
|
|
|
const removeExportsPlugin: Plugin = {
|
|
|
|
name: 'remove-sw-exports',
|
|
|
|
generateBundle(_options, bundle) {
|
|
|
|
for (const [name, chunk] of Object.entries(bundle)) {
|
|
|
|
if (chunk.type === 'chunk' && name === 'sw.js') {
|
|
|
|
chunk.code = chunk.code.replace(/export{.*};\s*$/g, '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-09-13 17:04:17 +00:00
|
|
|
export default defineConfig({
|
|
|
|
root: 'app',
|
|
|
|
build: {
|
|
|
|
outDir: '../static',
|
|
|
|
assetsDir: 'packs',
|
2023-09-15 00:04:07 +00:00
|
|
|
assetsInlineLimit: 0,
|
2023-09-14 23:04:00 +00:00
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
|
|
|
main: 'app/index.html',
|
|
|
|
sw: 'app/soapbox/service-worker/sw.ts',
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
entryFileNames: ({ name }) => {
|
|
|
|
switch (name) {
|
|
|
|
case 'sw':
|
|
|
|
return 'sw.js';
|
|
|
|
default:
|
|
|
|
return 'packs/[name]-[hash].js';
|
|
|
|
}
|
|
|
|
},
|
2023-09-15 01:37:49 +00:00
|
|
|
manualChunks: (id) => {
|
|
|
|
if (id.includes('soapbox/service-worker')) {
|
|
|
|
return 'sw';
|
|
|
|
}
|
|
|
|
return 'main';
|
2023-09-14 23:04:00 +00:00
|
|
|
},
|
2023-09-15 00:14:16 +00:00
|
|
|
assetFileNames: 'packs/assets/[name]-[hash].[ext]',
|
|
|
|
chunkFileNames: 'packs/js/[name]-[hash].js',
|
2023-09-14 23:04:00 +00:00
|
|
|
},
|
|
|
|
},
|
2023-09-13 17:04:17 +00:00
|
|
|
},
|
2023-09-13 17:24:49 +00:00
|
|
|
server: {
|
|
|
|
port: 3036,
|
|
|
|
},
|
2023-09-13 17:04:17 +00:00
|
|
|
plugins: [
|
|
|
|
// @ts-ignore
|
|
|
|
vitePluginRequire.default(),
|
|
|
|
createHtmlPlugin({
|
|
|
|
template: 'index.html',
|
|
|
|
}),
|
|
|
|
react({
|
|
|
|
// Use React plugin in all *.jsx and *.tsx files
|
|
|
|
include: '**/*.{jsx,tsx}',
|
2023-09-13 21:35:41 +00:00
|
|
|
babel: {
|
|
|
|
configFile: './babel.config.cjs',
|
|
|
|
},
|
2023-09-13 17:04:17 +00:00
|
|
|
}),
|
|
|
|
compileTime(),
|
|
|
|
viteStaticCopy({
|
|
|
|
targets: [{
|
|
|
|
src: '../node_modules/twemoji/assets/svg/*',
|
|
|
|
dest: 'packs/emoji/',
|
|
|
|
}],
|
|
|
|
}),
|
2023-09-15 01:37:49 +00:00
|
|
|
removeExportsPlugin,
|
2023-09-13 17:04:17 +00:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: [
|
|
|
|
{ find: 'soapbox', replacement: path.resolve(__dirname, 'app', 'soapbox') },
|
|
|
|
{ find: 'assets', replacement: path.resolve(__dirname, 'app', 'assets') },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
assetsInclude: ['**/*.oga'],
|
|
|
|
});
|