mirror of
https://github.com/gitlabhq/gitlabhq.git
synced 2025-07-21 23:37:47 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { stat, mkdir, copyFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
import { defineConfig } from 'vite';
|
||||
@ -6,6 +7,7 @@ import vue from '@vitejs/plugin-vue2';
|
||||
import graphql from '@rollup/plugin-graphql';
|
||||
import RubyPlugin from 'vite-plugin-ruby';
|
||||
import chokidar from 'chokidar';
|
||||
import globby from 'globby';
|
||||
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
|
||||
import webpackConfig from './config/webpack.config';
|
||||
import {
|
||||
@ -13,6 +15,7 @@ import {
|
||||
IS_JH,
|
||||
SOURCEGRAPH_PUBLIC_PATH,
|
||||
GITLAB_WEB_IDE_PUBLIC_PATH,
|
||||
copyFilesPatterns,
|
||||
} from './config/webpack.constants';
|
||||
/* eslint-disable import/extensions */
|
||||
import { viteCSSCompilerPlugin } from './scripts/frontend/lib/compile_css.mjs';
|
||||
@ -90,6 +93,76 @@ const autoRestartPlugin = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a simple-reimplementation of the copy-webpack-plugin
|
||||
*
|
||||
* it also uses the `globby` package under the hood, and _only_ allows for copying
|
||||
* 1. absolute paths
|
||||
* 2. files and directories.
|
||||
*/
|
||||
function viteCopyPlugin({ patterns }) {
|
||||
return {
|
||||
name: 'viteCopyPlugin',
|
||||
async configureServer() {
|
||||
console.warn('Start copying files...');
|
||||
let count = 0;
|
||||
|
||||
const allTheFiles = patterns.map(async (patternEntry) => {
|
||||
const { from, to, globOptions = {} } = patternEntry;
|
||||
|
||||
// By only supporting absolute paths we simplify
|
||||
// the implementation a lot
|
||||
if (!path.isAbsolute(from)) {
|
||||
throw new Error(`'from' path is not absolute: ${path}`);
|
||||
}
|
||||
if (!path.isAbsolute(to)) {
|
||||
throw new Error(`'to' path is not absolute: ${path}`);
|
||||
}
|
||||
|
||||
let pattern = '';
|
||||
let sourceRoot = '';
|
||||
const fromStat = await stat(from);
|
||||
if (fromStat.isDirectory()) {
|
||||
sourceRoot = from;
|
||||
pattern = path.join(from, '**/*');
|
||||
} else if (fromStat.isFile()) {
|
||||
sourceRoot = path.dirname(from);
|
||||
pattern = from;
|
||||
} else {
|
||||
// No need to support globs, because we do not
|
||||
// use them yet...
|
||||
throw new Error('Our implementation does not support globs.');
|
||||
}
|
||||
|
||||
globOptions.dot = globOptions.dot ?? true;
|
||||
|
||||
const paths = await globby(pattern, globOptions);
|
||||
|
||||
return paths.map((srcPath) => {
|
||||
const targetPath = path.join(to, path.relative(sourceRoot, srcPath));
|
||||
return { srcPath, targetPath };
|
||||
});
|
||||
});
|
||||
|
||||
const srcTargetMap = (await Promise.all(allTheFiles)).flat();
|
||||
|
||||
await Promise.all(
|
||||
srcTargetMap.map(async ({ srcPath, targetPath }) => {
|
||||
try {
|
||||
await mkdir(path.dirname(targetPath), { recursive: true });
|
||||
await copyFile(srcPath, targetPath);
|
||||
count += 1;
|
||||
} catch (e) {
|
||||
console.warn(`Could not copy ${srcPath} => ${targetPath}`);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
console.warn(`Done copying ${count} files...`);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
cacheDir: path.resolve(__dirname, 'tmp/cache/vite'),
|
||||
resolve: {
|
||||
@ -110,6 +183,9 @@ export default defineConfig({
|
||||
plugins: [
|
||||
viteCSSCompilerPlugin({ shouldWatch: viteGDKConfig.hmr !== null }),
|
||||
viteTailwindCompilerPlugin({ shouldWatch: viteGDKConfig.hmr !== null }),
|
||||
viteCopyPlugin({
|
||||
patterns: copyFilesPatterns,
|
||||
}),
|
||||
viteGDKConfig.enabled ? autoRestartPlugin : null,
|
||||
fixedRubyPlugin,
|
||||
vue({
|
||||
|
Reference in New Issue
Block a user