fix
This commit is contained in:
@@ -4,7 +4,7 @@ import { KintoneRestAPIClient } from '@kintone/rest-api-client';
|
|||||||
(function (PLUGIN_ID) {
|
(function (PLUGIN_ID) {
|
||||||
kintone.events.on('mobile.app.record.index.show', () => {
|
kintone.events.on('mobile.app.record.index.show', () => {
|
||||||
// App id
|
// App id
|
||||||
const appId = kintone.app.getId()?.toString();
|
const appId = kintone.mobile.app.getId()?.toString();
|
||||||
if (!appId) return;
|
if (!appId) return;
|
||||||
|
|
||||||
// get setting
|
// get setting
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import vue from '@vitejs/plugin-vue'
|
|||||||
import copy from "rollup-plugin-copy";
|
import copy from "rollup-plugin-copy";
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as child_process from 'child_process';
|
||||||
import Components from 'unplugin-vue-components/vite';
|
import Components from 'unplugin-vue-components/vite';
|
||||||
import RSA from 'node-rsa';
|
import RSA from 'node-rsa';
|
||||||
|
|
||||||
@@ -63,9 +64,59 @@ function replaceKucTagsPlugin() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to build IIFE versions of desktop and mobile scripts
|
||||||
|
function buildIIFEVersions() {
|
||||||
|
return {
|
||||||
|
name: 'iife-builder',
|
||||||
|
buildStart() {
|
||||||
|
console.log('Building IIFE versions...');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Build desktop IIFE
|
||||||
|
console.log('Building desktop IIFE...');
|
||||||
|
child_process.execSync('npx vite build --config vite.desktop.config.ts', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
// Build mobile IIFE
|
||||||
|
console.log('Building mobile IIFE...');
|
||||||
|
child_process.execSync('npx vite build --config vite.mobile.config.ts', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
console.log('IIFE builds completed successfully.');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error building IIFE versions:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
generateBundle(options, bundle) {
|
||||||
|
// Copy and overwrite the main dist/src/js files with IIFE versions
|
||||||
|
const desktopIIFEPath = path.resolve(__dirname, 'dist-temp/desktop/desktop.js');
|
||||||
|
const mobileIIFEPath = path.resolve(__dirname, 'dist-temp/mobile/mobile.js');
|
||||||
|
const destDir = path.resolve(__dirname, 'dist/src/js');
|
||||||
|
|
||||||
|
if (fs.existsSync(desktopIIFEPath)) {
|
||||||
|
fs.mkdirSync(destDir, { recursive: true });
|
||||||
|
fs.copyFileSync(desktopIIFEPath, path.join(destDir, 'desktop.js'));
|
||||||
|
console.log('Copied desktop.js to dist/src/js/');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(mobileIIFEPath)) {
|
||||||
|
fs.mkdirSync(destDir, { recursive: true });
|
||||||
|
fs.copyFileSync(mobileIIFEPath, path.join(destDir, 'mobile.js'));
|
||||||
|
console.log('Copied mobile.js to dist/src/js/');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up dist-temp directory
|
||||||
|
if (fs.existsSync(path.resolve(__dirname, 'dist-temp'))) {
|
||||||
|
fs.rmSync(path.resolve(__dirname, 'dist-temp'), { recursive: true, force: true });
|
||||||
|
console.log('Cleaned up dist-temp directory');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
|
buildIIFEVersions(),
|
||||||
vue({
|
vue({
|
||||||
template: {
|
template: {
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
@@ -77,6 +128,7 @@ export default defineConfig({
|
|||||||
copy({
|
copy({
|
||||||
targets: [
|
targets: [
|
||||||
{ src: 'dist/index.html', dest: 'dist/src/html', rename: 'config.html' },
|
{ src: 'dist/index.html', dest: 'dist/src/html', rename: 'config.html' },
|
||||||
|
{ src: 'src/manifest.json', dest: 'dist/src' },
|
||||||
{ src: 'src/assets/*.js', dest: 'dist/src/js' },
|
{ src: 'src/assets/*.js', dest: 'dist/src/js' },
|
||||||
{ src: 'src/assets/*.png', dest: 'dist/src/image' },
|
{ src: 'src/assets/*.png', dest: 'dist/src/image' },
|
||||||
{ src: 'src/css/*', dest: 'dist/src/css' },
|
{ src: 'src/css/*', dest: 'dist/src/css' },
|
||||||
@@ -84,40 +136,6 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
hook: 'writeBundle' // 指定在何时复制文件
|
hook: 'writeBundle' // 指定在何时复制文件
|
||||||
}),
|
}),
|
||||||
{
|
|
||||||
name: 'manifest-updater',
|
|
||||||
writeBundle() {
|
|
||||||
try {
|
|
||||||
const manifestPath = path.resolve(__dirname, 'dist/src/manifest.json');
|
|
||||||
const destDir = path.dirname(manifestPath);
|
|
||||||
fs.mkdirSync(destDir, { recursive: true });
|
|
||||||
fs.copyFileSync(path.resolve(__dirname, 'src/manifest.json'), manifestPath);
|
|
||||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
||||||
const viteManifestPath = path.resolve(__dirname, 'dist/.vite/manifest.json');
|
|
||||||
if (!fs.existsSync(viteManifestPath)) return;
|
|
||||||
|
|
||||||
const viteManifest = JSON.parse(fs.readFileSync(viteManifestPath, 'utf-8'));
|
|
||||||
|
|
||||||
// 收集所有生成的 chunk 文件
|
|
||||||
const chunkFiles: string[] = [];
|
|
||||||
Object.values(viteManifest).forEach((value: any) => {
|
|
||||||
if (value.file && value.file.endsWith('.chunk.js')) {
|
|
||||||
chunkFiles.push('js/' + path.basename(value.file));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新 desktop 和 mobile 的 js 数组,包含 chunk 文件
|
|
||||||
if (chunkFiles.length > 0) {
|
|
||||||
manifest.desktop.js = ['js/kuc.min.js', 'js/desktop.js', ...chunkFiles];
|
|
||||||
manifest.mobile.js = ['js/kuc.min.js', 'js/mobile.js', ...chunkFiles];
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error updating manifest:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
replaceKucTagsPlugin()
|
replaceKucTagsPlugin()
|
||||||
],
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
@@ -129,19 +147,15 @@ export default defineConfig({
|
|||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: {
|
input: {
|
||||||
config: path.resolve(__dirname, 'index.html'),
|
config: path.resolve(__dirname, 'index.html'),
|
||||||
desktop: path.resolve(__dirname, 'src/js/desktop.ts'),
|
|
||||||
mobile: path.resolve(__dirname, 'src/js/mobile.ts'),
|
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
entryFileNames: (chunkInfo) => {
|
entryFileNames: (chunkInfo) => {
|
||||||
return 'src/js/[name].js'; // 默认处理为 JS 文件
|
return 'src/js/[name].js'; // 默认处理为 JS 文件
|
||||||
},
|
},
|
||||||
chunkFileNames: 'src/js/[name]-[hash].chunk.js',
|
|
||||||
assetFileNames: 'src/[ext]/[name].[ext]',
|
assetFileNames: 'src/[ext]/[name].[ext]',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
sourcemap: 'inline',
|
sourcemap: 'inline',
|
||||||
manifest: true,
|
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
KUC_VERSION: JSON.stringify(dottedVersion),
|
KUC_VERSION: JSON.stringify(dottedVersion),
|
||||||
|
|||||||
33
vite.desktop.config.ts
Normal file
33
vite.desktop.config.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
// Read kintone-ui-component version from package.json
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf-8'));
|
||||||
|
const kucVersion = packageJson.dependencies['kintone-ui-component'];
|
||||||
|
const dottedVersion = kucVersion; // e.g., 1.22.0 -> 1.22.0
|
||||||
|
|
||||||
|
export default {
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: path.resolve(__dirname, 'src/js/desktop.ts'),
|
||||||
|
name: 'DesktopPlugin',
|
||||||
|
formats: ['iife'],
|
||||||
|
fileName: () => 'desktop.js'
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
external: ['kintone'],
|
||||||
|
output: {
|
||||||
|
globals: {
|
||||||
|
kintone: 'kintone'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sourcemap: false,
|
||||||
|
emptyOutDir: false,
|
||||||
|
outDir: path.resolve(__dirname, 'dist-temp/desktop')
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
KUC_VERSION: JSON.stringify(dottedVersion),
|
||||||
|
KUC_VERSION_DASHED: JSON.stringify(dottedVersion.replace(/\./g, '-'))
|
||||||
|
}
|
||||||
|
}
|
||||||
33
vite.mobile.config.ts
Normal file
33
vite.mobile.config.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
// Read kintone-ui-component version from package.json
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf-8'));
|
||||||
|
const kucVersion = packageJson.dependencies['kintone-ui-component'];
|
||||||
|
const dottedVersion = kucVersion; // e.g., 1.22.0 -> 1.22.0
|
||||||
|
|
||||||
|
export default {
|
||||||
|
build: {
|
||||||
|
lib: {
|
||||||
|
entry: path.resolve(__dirname, 'src/js/mobile.ts'),
|
||||||
|
name: 'MobilePlugin',
|
||||||
|
formats: ['iife'],
|
||||||
|
fileName: () => 'mobile.js'
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
external: ['kintone'],
|
||||||
|
output: {
|
||||||
|
globals: {
|
||||||
|
kintone: 'kintone'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sourcemap: false,
|
||||||
|
emptyOutDir: false,
|
||||||
|
outDir: path.resolve(__dirname, 'dist-temp/mobile')
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
KUC_VERSION: JSON.stringify(dottedVersion),
|
||||||
|
KUC_VERSION_DASHED: JSON.stringify(dottedVersion.replace(/\./g, '-'))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user