2023-03-14 17:45:27 +03:00
|
|
|
import {resolve} from 'path';
|
|
|
|
import fs from 'fs/promises';
|
|
|
|
|
|
|
|
import {defineConfig} from 'vitest/config';
|
|
|
|
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
|
|
|
|
import reactPlugin from '@vitejs/plugin-react';
|
|
|
|
import svgrPlugin from 'vite-plugin-svgr';
|
|
|
|
|
|
|
|
import pkg from './package.json';
|
|
|
|
|
|
|
|
import {SUPPORTED_LOCALES} from '@tryghost/i18n';
|
|
|
|
|
|
|
|
export default defineConfig((config) => {
|
|
|
|
const outputFileName = pkg.name[0] === '@' ? pkg.name.slice(pkg.name.indexOf('/') + 1) : pkg.name;
|
|
|
|
|
|
|
|
return {
|
2023-11-15 11:51:52 +03:00
|
|
|
logLevel: process.env.CI ? 'info' : 'warn',
|
2023-03-14 17:45:27 +03:00
|
|
|
clearScreen: false,
|
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(config.mode),
|
2023-06-02 12:31:06 +03:00
|
|
|
REACT_APP_VERSION: JSON.stringify(process.env.npm_package_version)
|
2023-03-14 17:45:27 +03:00
|
|
|
},
|
2023-06-02 12:32:13 +03:00
|
|
|
preview: {
|
|
|
|
port: 4175
|
|
|
|
},
|
2023-03-14 17:45:27 +03:00
|
|
|
server: {
|
2023-06-02 12:31:06 +03:00
|
|
|
port: 5368
|
2023-03-14 17:45:27 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
cssInjectedByJsPlugin(),
|
|
|
|
reactPlugin(),
|
2023-06-02 12:31:06 +03:00
|
|
|
svgrPlugin()
|
2023-03-14 17:45:27 +03:00
|
|
|
],
|
|
|
|
esbuild: {
|
2023-06-02 12:31:06 +03:00
|
|
|
loader: 'jsx',
|
2023-03-14 17:45:27 +03:00
|
|
|
include: /src\/.*\.jsx?$/,
|
2023-06-02 12:31:06 +03:00
|
|
|
exclude: []
|
2023-03-14 17:45:27 +03:00
|
|
|
},
|
|
|
|
optimizeDeps: {
|
|
|
|
esbuildOptions: {
|
|
|
|
plugins: [
|
|
|
|
{
|
2023-06-02 12:31:06 +03:00
|
|
|
name: 'load-js-files-as-jsx',
|
2023-03-14 17:45:27 +03:00
|
|
|
setup(build) {
|
2023-06-02 12:31:06 +03:00
|
|
|
build.onLoad({filter: /src\/.*\.js$/}, async args => ({
|
|
|
|
loader: 'jsx',
|
|
|
|
contents: await fs.readFile(args.path, 'utf8')
|
2023-03-14 17:45:27 +03:00
|
|
|
}));
|
2023-06-02 12:31:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-03-14 17:45:27 +03:00
|
|
|
},
|
|
|
|
build: {
|
|
|
|
outDir: resolve(__dirname, 'umd'),
|
|
|
|
emptyOutDir: true,
|
2023-11-15 11:04:18 +03:00
|
|
|
reportCompressedSize: false,
|
2023-03-14 17:45:27 +03:00
|
|
|
minify: true,
|
|
|
|
sourcemap: true,
|
|
|
|
cssCodeSplit: false,
|
|
|
|
lib: {
|
|
|
|
entry: resolve(__dirname, 'src/index.js'),
|
|
|
|
formats: ['umd'],
|
|
|
|
name: pkg.name,
|
2023-06-02 12:31:06 +03:00
|
|
|
fileName: format => `${outputFileName}.min.js`
|
2023-03-14 17:45:27 +03:00
|
|
|
},
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
2023-06-02 12:31:06 +03:00
|
|
|
manualChunks: false
|
2023-03-14 17:45:27 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
commonjsOptions: {
|
|
|
|
include: [/ghost/, /node_modules/],
|
2023-06-14 15:33:47 +03:00
|
|
|
dynamicRequireRoot: '../../',
|
|
|
|
dynamicRequireTargets: SUPPORTED_LOCALES.map(locale => `../../ghost/i18n/locales/${locale}/portal.json`)
|
2023-03-14 17:45:27 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
test: {
|
|
|
|
globals: true,
|
|
|
|
environment: 'jsdom',
|
|
|
|
setupFiles: './src/setupTests.js',
|
|
|
|
testTimeout: 10000
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|