Defining vite env vars with git info
This commit is contained in:
parent
da76e30fc4
commit
7997138c5e
|
@ -157,6 +157,7 @@ const Map: Component = () => {
|
||||||
params: {
|
params: {
|
||||||
...params,
|
...params,
|
||||||
},
|
},
|
||||||
|
lastCommit: import.meta.env.VITE_GIT_COMMIT_HASH,
|
||||||
});
|
});
|
||||||
setState({
|
setState({
|
||||||
provider: params.provider,
|
provider: params.provider,
|
||||||
|
@ -290,7 +291,7 @@ const Map: Component = () => {
|
||||||
moveTolerance: 10,
|
moveTolerance: 10,
|
||||||
interactions: new Collection<Interaction>([
|
interactions: new Collection<Interaction>([
|
||||||
new DragRotate(),
|
new DragRotate(),
|
||||||
// new DoubleClickZoom(),
|
// new DoubleClickZoom(),
|
||||||
new DragPan(),
|
new DragPan(),
|
||||||
new PinchRotate(),
|
new PinchRotate(),
|
||||||
new PinchZoom(),
|
new PinchZoom(),
|
||||||
|
|
174
vite.config.ts
174
vite.config.ts
|
@ -5,6 +5,7 @@ import { defineConfig } from 'vite';
|
||||||
import solidPlugin from 'vite-plugin-solid';
|
import solidPlugin from 'vite-plugin-solid';
|
||||||
import suidPlugin from '@suid/vite-plugin';
|
import suidPlugin from '@suid/vite-plugin';
|
||||||
import solidSvg from 'vite-plugin-solid-svg';
|
import solidSvg from 'vite-plugin-solid-svg';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
// yarn add --dev @esbuild-plugins/node-globals-polyfill
|
// yarn add --dev @esbuild-plugins/node-globals-polyfill
|
||||||
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
|
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
|
||||||
|
@ -13,85 +14,100 @@ import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfil
|
||||||
// You don't need to add this to deps, it's included by @esbuild-plugins/node-modules-polyfill
|
// You don't need to add this to deps, it's included by @esbuild-plugins/node-modules-polyfill
|
||||||
import rollupNodePolyFill from 'rollup-plugin-node-polyfills';
|
import rollupNodePolyFill from 'rollup-plugin-node-polyfills';
|
||||||
|
|
||||||
export default defineConfig(({ command, mode, ssrBuild }) => ({
|
export default defineConfig(({ command, mode, ssrBuild }) => {
|
||||||
plugins: [
|
const commitDate = execSync('git log -1 --format=%cI').toString().trimEnd();
|
||||||
suidPlugin(),
|
const branchName = execSync('git rev-parse --abbrev-ref HEAD')
|
||||||
solidPlugin(),
|
.toString()
|
||||||
solidSvg({
|
.trimEnd();
|
||||||
/**
|
const commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
|
||||||
* If true, will export as JSX component if `as` isn't specified.
|
const lastCommitMessage = execSync('git show -s --format=%s')
|
||||||
*
|
.toString()
|
||||||
* Otherwise will export as url, or as JSX component if '?as=component-solid'
|
.trimEnd();
|
||||||
*/
|
|
||||||
defaultAsComponent: false,
|
process.env.VITE_GIT_COMMIT_DATE = commitDate;
|
||||||
}),
|
process.env.VITE_GIT_BRANCH_NAME = branchName;
|
||||||
],
|
process.env.VITE_GIT_COMMIT_HASH = commitHash;
|
||||||
test: {
|
process.env.VITE_GIT_LAST_COMMIT_MESSAGE = lastCommitMessage;
|
||||||
environment: 'jsdom',
|
return {
|
||||||
globals: true,
|
plugins: [
|
||||||
transformMode: {
|
suidPlugin(),
|
||||||
web: [/\.[jt]sx?$/],
|
solidPlugin(),
|
||||||
|
solidSvg({
|
||||||
|
/**
|
||||||
|
* If true, will export as JSX component if `as` isn't specified.
|
||||||
|
*
|
||||||
|
* Otherwise will export as url, or as JSX component if '?as=component-solid'
|
||||||
|
*/
|
||||||
|
defaultAsComponent: false,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
test: {
|
||||||
|
environment: 'jsdom',
|
||||||
|
globals: true,
|
||||||
|
transformMode: {
|
||||||
|
web: [/\.[jt]sx?$/],
|
||||||
|
},
|
||||||
|
setupFiles: './setupVitest.ts',
|
||||||
|
// solid needs to be inline to work around
|
||||||
|
// a resolution issue in vitest:
|
||||||
|
deps: {
|
||||||
|
inline: [/solid-js/],
|
||||||
|
},
|
||||||
|
// if you have few tests, try commenting one
|
||||||
|
// or both out to improve performance:
|
||||||
|
threads: false,
|
||||||
|
isolate: false,
|
||||||
},
|
},
|
||||||
setupFiles: './setupVitest.ts',
|
build: {
|
||||||
// solid needs to be inline to work around
|
target: 'esnext',
|
||||||
// a resolution issue in vitest:
|
polyfillDynamicImport: false,
|
||||||
deps: {
|
|
||||||
inline: [/solid-js/],
|
|
||||||
},
|
},
|
||||||
// if you have few tests, try commenting one
|
resolve: {
|
||||||
// or both out to improve performance:
|
conditions: ['development', 'browser'],
|
||||||
threads: false,
|
alias: {
|
||||||
isolate: false,
|
// This Rollup aliases are extracted from @esbuild-plugins/node-modules-polyfill,
|
||||||
},
|
// see https://github.com/remorses/esbuild-plugins/blob/master/node-modules-polyfill/src/polyfills.ts
|
||||||
build: {
|
// process and buffer are excluded because already managed
|
||||||
target: 'esnext',
|
// by node-globals-polyfill
|
||||||
polyfillDynamicImport: false,
|
util: 'rollup-plugin-node-polyfills/polyfills/util',
|
||||||
},
|
sys: 'util',
|
||||||
resolve: {
|
events: 'rollup-plugin-node-polyfills/polyfills/events',
|
||||||
conditions: ['development', 'browser'],
|
stream: 'rollup-plugin-node-polyfills/polyfills/stream',
|
||||||
alias: {
|
path: 'rollup-plugin-node-polyfills/polyfills/path',
|
||||||
// This Rollup aliases are extracted from @esbuild-plugins/node-modules-polyfill,
|
querystring: 'rollup-plugin-node-polyfills/polyfills/qs',
|
||||||
// see https://github.com/remorses/esbuild-plugins/blob/master/node-modules-polyfill/src/polyfills.ts
|
punycode: 'rollup-plugin-node-polyfills/polyfills/punycode',
|
||||||
// process and buffer are excluded because already managed
|
url: 'rollup-plugin-node-polyfills/polyfills/url',
|
||||||
// by node-globals-polyfill
|
string_decoder: 'rollup-plugin-node-polyfills/polyfills/string-decoder',
|
||||||
util: 'rollup-plugin-node-polyfills/polyfills/util',
|
http: 'rollup-plugin-node-polyfills/polyfills/http',
|
||||||
sys: 'util',
|
https: 'rollup-plugin-node-polyfills/polyfills/http',
|
||||||
events: 'rollup-plugin-node-polyfills/polyfills/events',
|
os: 'rollup-plugin-node-polyfills/polyfills/os',
|
||||||
stream: 'rollup-plugin-node-polyfills/polyfills/stream',
|
assert: 'rollup-plugin-node-polyfills/polyfills/assert',
|
||||||
path: 'rollup-plugin-node-polyfills/polyfills/path',
|
constants: 'rollup-plugin-node-polyfills/polyfills/constants',
|
||||||
querystring: 'rollup-plugin-node-polyfills/polyfills/qs',
|
_stream_duplex:
|
||||||
punycode: 'rollup-plugin-node-polyfills/polyfills/punycode',
|
'rollup-plugin-node-polyfills/polyfills/readable-stream/duplex',
|
||||||
url: 'rollup-plugin-node-polyfills/polyfills/url',
|
_stream_passthrough:
|
||||||
string_decoder: 'rollup-plugin-node-polyfills/polyfills/string-decoder',
|
'rollup-plugin-node-polyfills/polyfills/readable-stream/passthrough',
|
||||||
http: 'rollup-plugin-node-polyfills/polyfills/http',
|
_stream_readable:
|
||||||
https: 'rollup-plugin-node-polyfills/polyfills/http',
|
'rollup-plugin-node-polyfills/polyfills/readable-stream/readable',
|
||||||
os: 'rollup-plugin-node-polyfills/polyfills/os',
|
_stream_writable:
|
||||||
assert: 'rollup-plugin-node-polyfills/polyfills/assert',
|
'rollup-plugin-node-polyfills/polyfills/readable-stream/writable',
|
||||||
constants: 'rollup-plugin-node-polyfills/polyfills/constants',
|
_stream_transform:
|
||||||
_stream_duplex:
|
'rollup-plugin-node-polyfills/polyfills/readable-stream/transform',
|
||||||
'rollup-plugin-node-polyfills/polyfills/readable-stream/duplex',
|
timers: 'rollup-plugin-node-polyfills/polyfills/timers',
|
||||||
_stream_passthrough:
|
console: 'rollup-plugin-node-polyfills/polyfills/console',
|
||||||
'rollup-plugin-node-polyfills/polyfills/readable-stream/passthrough',
|
vm: 'rollup-plugin-node-polyfills/polyfills/vm',
|
||||||
_stream_readable:
|
zlib: 'rollup-plugin-node-polyfills/polyfills/zlib',
|
||||||
'rollup-plugin-node-polyfills/polyfills/readable-stream/readable',
|
tty: 'rollup-plugin-node-polyfills/polyfills/tty',
|
||||||
_stream_writable:
|
domain: 'rollup-plugin-node-polyfills/polyfills/domain',
|
||||||
'rollup-plugin-node-polyfills/polyfills/readable-stream/writable',
|
},
|
||||||
_stream_transform:
|
|
||||||
'rollup-plugin-node-polyfills/polyfills/readable-stream/transform',
|
|
||||||
timers: 'rollup-plugin-node-polyfills/polyfills/timers',
|
|
||||||
console: 'rollup-plugin-node-polyfills/polyfills/console',
|
|
||||||
vm: 'rollup-plugin-node-polyfills/polyfills/vm',
|
|
||||||
zlib: 'rollup-plugin-node-polyfills/polyfills/zlib',
|
|
||||||
tty: 'rollup-plugin-node-polyfills/polyfills/tty',
|
|
||||||
domain: 'rollup-plugin-node-polyfills/polyfills/domain',
|
|
||||||
},
|
},
|
||||||
},
|
define:
|
||||||
define:
|
command === 'serve'
|
||||||
command === 'serve'
|
? {
|
||||||
? {
|
// By default, Vite doesn't include shims for NodeJS/
|
||||||
// By default, Vite doesn't include shims for NodeJS/
|
// necessary for segment analytics lib to work
|
||||||
// necessary for segment analytics lib to work
|
global: {},
|
||||||
global: {},
|
}
|
||||||
}
|
: {},
|
||||||
: {},
|
};
|
||||||
}));
|
});
|
||||||
|
|
Loading…
Reference in New Issue