| 1 |
import { defineConfig } from "vite"; |
| 2 |
import path from "path"; |
| 3 |
import react from "@vitejs/plugin-react"; |
| 4 |
|
| 5 |
const wp = ["blocks", "editor", "block-editor", "data", "blocks"]; |
| 6 |
|
| 7 |
const external: Record<string, any> = { |
| 8 |
"jquery": "jQuery", |
| 9 |
"lodash-es": "lodash", |
| 10 |
"lodash": "lodash", |
| 11 |
"moment": "moment", |
| 12 |
"react-dom": "ReactDOM", |
| 13 |
"react": "React", |
| 14 |
}; |
| 15 |
|
| 16 |
wp.forEach(wpEntry => { |
| 17 |
external[`@wordpress/${wpEntry}`] = |
| 18 |
"wp." + |
| 19 |
wpEntry.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()); |
| 20 |
}); |
| 21 |
|
| 22 |
// https://vitejs.dev/config/ |
| 23 |
export default defineConfig({ |
| 24 |
plugins: [react()], |
| 25 |
build: { |
| 26 |
minify: "esbuild", |
| 27 |
outDir: path.resolve(__dirname, "../includes/Admin/assets"), |
| 28 |
lib: { |
| 29 |
entry: path.resolve(__dirname, "src/index.jsx"), |
| 30 |
name: "tableberg-admin-app", |
| 31 |
fileName: () => "tableberg-admin.build.js", |
| 32 |
formats: ["umd"], |
| 33 |
}, |
| 34 |
rollupOptions: { |
| 35 |
external: Object.keys(external), |
| 36 |
output: { |
| 37 |
globals: external, |
| 38 |
assetFileNames: assetInfo => { |
| 39 |
if (assetInfo.name === "style.css") { |
| 40 |
return "tableberg-admin-style.css"; |
| 41 |
} |
| 42 |
return assetInfo.name as string; |
| 43 |
}, |
| 44 |
}, |
| 45 |
}, |
| 46 |
cssCodeSplit: false, |
| 47 |
}, |
| 48 |
define: { |
| 49 |
"process.env.NODE_ENV": '"production"', |
| 50 |
}, |
| 51 |
}); |
| 52 |
|