Skip to content

Commit

Permalink
built tester by using multiple build
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsuhiko Maeno committed Jun 11, 2024
1 parent adb56af commit 767e8c0
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 76 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"main": "main.js",
"scripts": {
"dev": "vite --host --port 3333",
"build": "tsc && vite build",
"build": "tsc && vite build --mode Timeline",
"build:tester": "tsc && vite build --mode Tester",
"preview": "vite preview",
"lint:code": "biome lint ./",
"lint:style": "biome format ./",
Expand Down
5 changes: 2 additions & 3 deletions src/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//import './styles/main.sass'
import { TimelineOptions } from './types/definitions'
import { Timeline } from './SunorhcTimeline'
import { TimelineOptions } from '@/types/definitions'
import { Timeline } from '@/SunorhcTimeline'

// Set type of handling to dispatch plugin:
const creationType: number = 3
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Timeline } from './SunorhcTimeline'
import { Timeline } from '@/SunorhcTimeline'

export { Timeline }
2 changes: 1 addition & 1 deletion src/tester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupTester } from './SunorhcTimelineTester'
import { setupTester } from '@/tester/SunorhcTimelineTester'

document.querySelector<HTMLDivElement>('#tester')!.innerHTML = `
<div id="sunorhc-timeline-tester"></div>
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/tester/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare var getRect: (element: HTMLElement) => DOMRect

interface Window {
SunorhcTimelineInstances: Record<string, Timeline>;
}
3 changes: 3 additions & 0 deletions src/tester/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { setupTester } from '@/tester/SunorhcTimelineTester'

export { setupTester }
156 changes: 86 additions & 70 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,99 @@ import * as path from 'path'
import basicSsl from '@vitejs/plugin-basic-ssl'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
define: {
//__DEV__: mode === 'development',
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
},
root: '',
base: '/',
publicDir: 'public',
build: {
outDir: './dist',
emptyOutDir: true,
manifest: true,
lib: {
entry: path.resolve(__dirname, 'src/main.ts'),
name: 'Sunorhc',
formats: ['es', 'umd'],
fileName: (format) => `SunorhcTimeline.${format}.js`
export default defineConfig(({ mode }) => {
const isMain = mode === 'Timeline'

return {
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
},
rollupOptions: {
external: [
'pino',
path.resolve(__dirname, 'src/dispatcher.ts'),
path.resolve(__dirname, 'src/SunorhcTimelineTester.ts'),
path.resolve(__dirname, 'src/tester.ts'),
/^.+(dispatcher|SunorhcTimelineTester|tester)\.ts$/,
/test/,
],
//input: [ 'src/index.html', ],
output: {
globals: {
pino: 'pino',
root: '',
base: '/',
publicDir: 'public',
build: {
outDir: './dist',
emptyOutDir: true,
manifest: true,
lib: {
entry: path.resolve(__dirname, 'src/main.ts'),
name: 'Sunorhc',
fileName: (format) => `SunorhcTimeline.${format}.js`
},
rollupOptions: {
input: isMain
? path.resolve(__dirname, 'src/main.ts')
: path.resolve(__dirname, 'src/tester/main.ts'),
output: {
globals: {
pino: 'pino',
},
entryFileNames: isMain ? 'assets/js/sunorhc.timeline.js' : `assets/js/${mode}.js`,// `assets/js/[name].js`,
chunkFileNames: `assets/js/[name].js`,
assetFileNames: (assetInfo) => {
if (/\.(gif|jpe?g|png|svg|webp)$/.test(assetInfo.name!)) {
return `assets/images/[name].[ext]`
} else if (/\.css$/.test(assetInfo.name!)) {
return 'assets/css/sunorhc.timeline.[ext]'// `assets/css/[name].[ext]`
} else {
return `assets/[name].[ext]`
}
},
format: 'umd',
inlineDynamicImports: false,
},
entryFileNames: `assets/js/[name].js`,
chunkFileNames: `assets/js/[name].js`,
assetFileNames: (assetInfo) => {
if (/\.(gif|jpe?g|png|svg|webp)$/.test(assetInfo.name!)) {
return `assets/images/[name].[ext]`
} else if (/\.css$/.test(assetInfo.name!)) {
return `assets/css/[name].[ext]`
} else {
return `assets/[name].[ext]`
external: (source, importer) => {
if (importer) {
//console.log(source, importer, isResolved)
if (importer.includes('src/main.ts')) {
return [
'pino',
path.resolve(__dirname, 'src/dispatcher.ts'),
path.resolve(__dirname, 'src/SunorhcTimelineTester.ts'),
path.resolve(__dirname, 'src/tester.ts'),
/tester/,
].includes(source)
}
if (importer.includes('src/tester/main.ts')) {
return [
'pino',
].includes(source)
}
}
return false
},
},
},
},
envDir: './',
plugins: [
basicSsl(),
tsconfigPaths({
root: './',
}),
],
css: {
postcss: './postcss.config.cjs'
},
test: {
globals: true,
environment: 'happy-dom',
setupFiles: ['./vitest.setup.ts'],// for using jest-dom
include: [
'test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
//'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
envDir: './',
plugins: [
basicSsl(),
tsconfigPaths({
root: './',
}),
],
//exclude: ['test/**/_*'],
coverage: {
provider: 'v8',// or 'istanbul'
reporter: ['text', 'json', 'html'],
reportsDirectory: 'docs/coverage',
exclude: [
'docs/**/*',
'mock/**/*',
'public/**/*',
'src/**/_*',
'postcss.config.cjs',
],
all: true,
css: {
postcss: './postcss.config.cjs'
},
test: {
globals: true,
environment: 'happy-dom',
setupFiles: ['./vitest.setup.ts'],// for using jest-dom
include: [
'test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
],
coverage: {
provider: 'v8',// or 'istanbul'
reporter: ['text', 'json', 'html'],
reportsDirectory: 'docs/coverage',
exclude: [
'docs/**/*',
'mock/**/*',
'public/**/*',
'src/**/_*',
'postcss.config.cjs',
],
all: true,
},
}
}
})

0 comments on commit 767e8c0

Please sign in to comment.