Skip to content

Commit

Permalink
Support windows in build (#3727)
Browse files Browse the repository at this point in the history
* Support windows in build

* Fix test import
  • Loading branch information
yayuyokitano committed May 16, 2023
1 parent 79b3364 commit 65418bd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
12 changes: 12 additions & 0 deletions scripts/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { resolve } from 'path';
import { normalizePath } from 'vite';

/**
* Folder names corresponding to build targets
*/
Expand Down Expand Up @@ -37,5 +40,14 @@ export function getBrowser() {
return browserName;
}

/**
* Resolve vite path in a cross-platform way
*
* @param paths - paths to resolve
*/
export function resolvePath(...paths: string[]) {
return normalizePath(resolve(...paths));
}

export const releaseTarget = process.argv.at(-1);
export const releaseType = process.argv.at(-2);
31 changes: 15 additions & 16 deletions vite.configs.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { UserConfig, normalizePath } from 'vite';
import { resolve } from 'path';
import { UserConfig } from 'vite';
import * as manifests from './manifest.config';
import solid from 'vite-plugin-solid';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import compileConnectors from './scripts/compile-connectors';
import makeManifest from './scripts/make-manifest';
import { isDev, releaseTarget } from 'scripts/util';
import { isDev, releaseTarget, resolvePath } from 'scripts/util';
import minifyImages from 'scripts/minify-images';
import generateIcons from 'scripts/generate-icons';

const dist = resolve(import.meta.url.slice(5), '..', 'build');
const root = resolve(import.meta.url.slice(5), '..', 'src');
const dist = resolvePath('build');
const root = resolvePath('src');
const builds = {
chrome: resolve(dist, 'chrome'),
firefox: resolve(dist, 'firefox'),
safari: resolve(dist, 'safariraw'),
error: resolve(dist, 'error'),
chrome: resolvePath(dist, 'chrome'),
firefox: resolvePath(dist, 'firefox'),
safari: resolvePath(dist, 'safariraw'),
error: resolvePath(dist, 'error'),
};

const common: UserConfig = {
Expand All @@ -39,11 +38,11 @@ export const buildBackground: UserConfig = {
...common,
build: {
minify: !isDev(),
outDir: resolve(distRoot(), 'background'),
outDir: resolvePath(distRoot(), 'background'),
emptyOutDir: true,
watch: isDev() ? {} : null,
lib: {
entry: resolve(root, 'core', 'background', 'main.ts'),
entry: resolvePath(root, 'core', 'background', 'main.ts'),
name: manifests.common.name,
formats: ['iife'],
},
Expand All @@ -60,11 +59,11 @@ export const buildContent: UserConfig = {
...common,
build: {
minify: !isDev(),
outDir: resolve(distRoot(), 'content'),
outDir: resolvePath(distRoot(), 'content'),
emptyOutDir: true,
watch: isDev() ? {} : null,
lib: {
entry: resolve(root, 'core', 'content', 'main.ts'),
entry: resolvePath(root, 'core', 'content', 'main.ts'),
name: manifests.common.name,
formats: ['iife'],
},
Expand All @@ -87,8 +86,8 @@ export const buildStart: UserConfig = {
sourcemap: isDev(),
rollupOptions: {
input: {
popup: resolve(root, 'ui', 'popup', 'index.html'),
options: resolve(root, 'ui', 'options', 'index.html'),
popup: resolvePath(root, 'ui', 'popup', 'index.html'),
options: resolvePath(root, 'ui', 'options', 'index.html'),
},
output: {},
},
Expand All @@ -100,7 +99,7 @@ export const buildStart: UserConfig = {
viteStaticCopy({
targets: [
{
src: normalizePath(resolve(root, '_locales')),
src: resolvePath(root, '_locales'),
dest: '',
},
],
Expand Down
6 changes: 3 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path';
import { resolvePath } from './scripts/util';
export default {
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'#': path.resolve(__dirname, './tests'),
'@': resolvePath(__dirname, './src'),
'#': resolvePath(__dirname, './tests'),
},
},
};

0 comments on commit 65418bd

Please sign in to comment.