2023-05-14 23:22:23 +00:00
|
|
|
import url from 'node:url';
|
|
|
|
import path from 'node:path';
|
|
|
|
import fs from 'node:fs';
|
|
|
|
|
2023-09-16 15:10:36 +00:00
|
|
|
import { defineConfig } from 'vitest/config';
|
2023-05-09 00:22:00 +00:00
|
|
|
import react from '@vitejs/plugin-react';
|
2023-05-10 21:01:32 +00:00
|
|
|
import wasm from 'vite-plugin-wasm';
|
2023-05-14 23:22:23 +00:00
|
|
|
import replace from '@rollup/plugin-replace';
|
2023-05-10 21:01:32 +00:00
|
|
|
import topLevelAwait from 'vite-plugin-top-level-await';
|
2023-05-21 23:29:27 +00:00
|
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
2023-05-07 19:11:16 +00:00
|
|
|
|
2023-09-16 14:11:11 +00:00
|
|
|
import { tryCommand } from './support/command';
|
2023-05-14 23:22:23 +00:00
|
|
|
|
2023-09-16 14:11:11 +00:00
|
|
|
const projectRoot = url.fileURLToPath(new URL('.', import.meta.url));
|
|
|
|
const pkg = JSON.parse(fs.readFileSync(projectRoot + '/package.json', 'utf-8'));
|
2023-05-14 23:22:23 +00:00
|
|
|
|
|
|
|
const COMMAND_GIT_VERSION = 'git describe --long --dirty --tags --always';
|
2023-09-16 14:11:11 +00:00
|
|
|
const shortCommit = tryCommand(COMMAND_GIT_VERSION, __dirname, 'unknown');
|
2023-05-14 23:22:23 +00:00
|
|
|
const version = `${pkg.version}-${shortCommit}`;
|
|
|
|
|
2023-05-07 19:11:16 +00:00
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
2023-06-09 00:00:57 +00:00
|
|
|
worker: {
|
|
|
|
format: 'es',
|
|
|
|
},
|
2023-05-13 19:03:32 +00:00
|
|
|
server: {
|
|
|
|
fs: {
|
2023-06-10 16:02:36 +00:00
|
|
|
// Note:
|
|
|
|
// This is _insecure_, but is required to get pnpm link to work.
|
|
|
|
// strict: false,
|
|
|
|
|
2023-05-13 19:03:32 +00:00
|
|
|
allow: [
|
|
|
|
'src',
|
|
|
|
'node_modules',
|
|
|
|
|
2023-06-10 16:02:36 +00:00
|
|
|
// Allow pnpm to link.
|
2023-05-21 13:34:27 +00:00
|
|
|
process.env.LIB_PARAKEET_JS_DIR || '../libparakeet-js',
|
2023-05-13 19:03:32 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2023-05-10 21:01:32 +00:00
|
|
|
base: './',
|
|
|
|
optimizeDeps: {
|
2023-06-11 15:21:10 +00:00
|
|
|
exclude: ['@jixun/libparakeet', 'sql.js'],
|
2023-05-10 21:01:32 +00:00
|
|
|
},
|
2023-05-14 23:22:23 +00:00
|
|
|
plugins: [
|
|
|
|
replace({
|
|
|
|
preventAssignment: true,
|
|
|
|
values: {
|
|
|
|
__APP_VERSION_SHORT__: pkg.version,
|
|
|
|
__APP_VERSION__: version,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
react(),
|
|
|
|
wasm(),
|
|
|
|
topLevelAwait(),
|
2023-05-21 23:29:27 +00:00
|
|
|
VitePWA({
|
|
|
|
registerType: 'prompt',
|
|
|
|
workbox: {
|
|
|
|
// Cache everything from dist
|
|
|
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,wasm}'],
|
|
|
|
},
|
|
|
|
manifest: {
|
|
|
|
display: 'standalone',
|
|
|
|
name: '音乐解锁 (Unlock Music)',
|
|
|
|
short_name: '音乐解锁',
|
|
|
|
lang: 'zh-cmn-Hans-CN',
|
|
|
|
description: '在现代浏览器解锁已购的加密音乐!',
|
|
|
|
theme_color: '#ffffff',
|
|
|
|
icons: [
|
|
|
|
{
|
|
|
|
src: 'pwa-192x192.png',
|
|
|
|
sizes: '192x192',
|
|
|
|
type: 'image/png',
|
|
|
|
purpose: 'maskable',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'pwa-512x512.png',
|
|
|
|
sizes: '512x512',
|
|
|
|
type: 'image/png',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
2023-05-14 23:22:23 +00:00
|
|
|
],
|
2023-05-09 00:22:00 +00:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'~': path.resolve(__dirname, 'src'),
|
2023-06-11 15:21:10 +00:00
|
|
|
'@nm': path.resolve(__dirname, 'node_modules'),
|
2023-12-21 22:49:12 +00:00
|
|
|
|
|
|
|
// workaround for vite, workbox (PWA) and Emscripten transpiled parakeet lib (use of `import("module")`)
|
2023-06-09 00:00:57 +00:00
|
|
|
module: path.resolve(__dirname, 'src', 'dummy.mjs'),
|
2023-05-09 00:22:00 +00:00
|
|
|
},
|
|
|
|
},
|
2023-05-15 20:39:58 +00:00
|
|
|
build: {
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks: {
|
2023-06-11 21:40:39 +00:00
|
|
|
reacts: ['react', 'react-dom', 'react-dropzone', 'react-promise-suspense', 'react-redux', '@reduxjs/toolkit'],
|
|
|
|
chakra: ['@chakra-ui/react', '@emotion/react', '@emotion/styled', 'framer-motion'],
|
|
|
|
icons: ['react-icons', '@chakra-ui/icons'],
|
|
|
|
utility: ['radash', 'nanoid', 'immer', 'react-syntax-highlighter'],
|
2023-05-15 20:39:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-09-16 15:10:36 +00:00
|
|
|
test: {
|
|
|
|
globals: true,
|
|
|
|
mockReset: true,
|
|
|
|
environment: 'jsdom',
|
|
|
|
setupFiles: ['src/test-utils/setup-jest.ts'],
|
|
|
|
alias: [
|
|
|
|
{
|
|
|
|
find: /^~\/(.*)/,
|
|
|
|
replacement: 'src/$1',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
// workaround: sql.js is not ESModule friendly, yet...
|
|
|
|
deps: {
|
|
|
|
optimizer: {
|
|
|
|
web: {
|
|
|
|
include: ['sql.js'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
api: {
|
|
|
|
port: 5174, // vite port + 1
|
|
|
|
},
|
|
|
|
coverage: {
|
|
|
|
provider: 'v8',
|
|
|
|
exclude: [
|
|
|
|
// default rules
|
|
|
|
'coverage/**',
|
|
|
|
'dist/**',
|
|
|
|
'packages/*/test{,s}/**',
|
|
|
|
'**/*.d.ts',
|
|
|
|
'cypress/**',
|
|
|
|
'test{,s}/**',
|
|
|
|
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
|
|
|
|
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
|
|
|
|
'**/*{.,-}spec.{js,cjs,mjs,ts,tsx,jsx}',
|
|
|
|
'**/__tests__/**',
|
|
|
|
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
|
|
|
|
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}',
|
|
|
|
|
|
|
|
// custom ones
|
|
|
|
'src/test-utils/**',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2023-05-09 00:22:00 +00:00
|
|
|
});
|