Skip to content

Commit

Permalink
enh: Support vite v5
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Dec 19, 2023
1 parent 39baceb commit 0904cfa
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 664 deletions.
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/appconfig.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

exports[`app config > replaces process.env 1`] = `
"/*! third party licenses: js/vendor.LICENSE.txt */
window.my_timezone={}.TZ;
var e={};window.my_timezone=e.TZ;
"
`;
3 changes: 2 additions & 1 deletion lib/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import type { UserConfig, UserConfigFn } from 'vite'
import type { PluginConfiguration as VitePluginInjectCSSOptions } from 'vite-plugin-css-injected-by-js/dist/esm/declarations/interface.js'
import type { BaseOptions, NodePolyfillsOptions } from './baseConfig.js'

import { mergeConfig } from 'vite'
Expand All @@ -15,6 +14,8 @@ import EmptyJSDirPlugin from './plugins/EmptyJSDir.js'
import replace from '@rollup/plugin-replace'
import injectCSSPlugin from 'vite-plugin-css-injected-by-js'

type VitePluginInjectCSSOptions = Parameters<typeof injectCSSPlugin>[0]

export const appName = process.env.npm_package_name
export const appVersion = process.env.npm_package_version
export const appNameSanitized = appName.replace(/[/\\]/, '-')
Expand Down
10 changes: 7 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

export { createAppConfig, type AppOptions } from './appConfig.js'
export { createBaseConfig, type BaseOptions } from './baseConfig.js'
export { createLibConfig, type LibraryOptions } from './libConfig.js'
export type { BaseOptions } from './baseConfig.js'
export type { AppOptions } from './appConfig'
export type { LibraryOptions } from './libConfig.js'

export { createBaseConfig } from './baseConfig.js'
export { createAppConfig } from './appConfig.js'
export { createLibConfig } from './libConfig.js'

Check warning on line 13 in lib/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/index.ts#L7-L13

Added lines #L7 - L13 were not covered by tests
4 changes: 2 additions & 2 deletions lib/libConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export const createLibConfig = (entries: { [entryAlias: string]: string }, optio
peerDeps: true, // Peer dependencies should be by definition external
deps: true, // Runtime dependencies: Same as with peer dependencies
...options.nodeExternalsOptions,
});
}) as Plugin

// Order is important, run the plugin first
(node as Plugin).enforce = 'pre'
node.enforce = 'pre'
const plugins = [
// Make dependencies external
node,
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/EmptyJSDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Plugin } from 'vite'

import { existsSync, rmSync } from 'node:fs'
import * as path from 'node:path'

import type { Plugin } from 'vite'

/**
* Vite plugin to clear the `js/` directory before emitting files
*/
Expand Down
Loading

0 comments on commit 0904cfa

Please sign in to comment.