Reputation: 65
I have a project that is structured like this (a shopify app)
extensions/
├─ checkout/
├─ theme-foo/
│ ├─ assets/
│ │ ├─ foo.min.js
│ │ ├─ asset.png
├─ theme-baz/
│ ├─ assets/
│ │ ├─ baz.min.js/
│ │ ├─ styles.css
extensions.source/
├─ theme-foo/
│ ├─ assets/
│ │ ├─ foo.ts
├─ theme-baz/
│ ├─ assets/
│ │ ├─ baz.ts
unrelated/
├─ untouchedFile.ts
vite.config.ts
vite.config.theme.ts
We want to have an extra vite config that spins up a watch process to do a spefific real-time minfication/source-map of ts and css files but we are failing at the moment.
Here's what we need:
Vite will be reading files and folders in the extensions.source
directory and will map them to the extensions
directory.
Here's some guidelines:
checkout
folder.extensions.source
folderunrelated
folder.We have the following (from chatgpt) but it's not working, we seem to not understand the process that well.
import { defineConfig } from 'vite';
import path from 'path';
export default defineConfig({
root: path.resolve(__dirname, 'extensions.source'), // Set root directory to extensions.source
build: {
outDir: '../extensions', // Adjust outDir path accordingly
minify: 'terser',
terserOptions: {
// Specify terser options here
},
target: 'es2015',
rollupOptions: {
input: {}, // Set input to an empty object to avoid specifying an HTML entry file
},
},
optimizeDeps: {
include: ['theme-*/*.{ts,css}'],
},
plugins: [
{
name: 'compile-typescript',
apply: 'build',
transform(src, id) {
const themeFolder = path.dirname(id);
const themeName = path.basename(themeFolder);
if (!themeName.startsWith('theme-')) {
return null;
}
if (id.endsWith('.ts')) {
return {
code: require('typescript').transpileModule(src, {
compilerOptions: {
module: require('typescript').ModuleKind.CommonJS,
sourceMap: true,
},
}).outputText,
map: null,
};
}
return null;
},
},
{
name: 'minify-css',
apply: 'build',
transform(src, id) {
if (id.endsWith('.css')) {
return require('css-minimizer').minify(src);
}
return null;
},
},
],
});
Are we totally misunderstand this? How do we approach this? We already have a vite config and we want to run this as a separate process side-by-side
Upvotes: 0
Views: 88