1
0
mirror of https://gitee.com/vant-contrib/vant.git synced 2025-04-06 03:57:59 +08:00

feat: generate entry file for nuxt3 ()

This commit is contained in:
neverland 2021-11-30 17:52:31 +08:00 committed by GitHub
parent bd236e9561
commit a60673013b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions
packages
vant-cli/src/compiler
vant

@ -1,8 +1,33 @@
import fse from 'fs-extra';
import { join } from 'path';
import { build } from 'vite';
import { getPackageJson } from '../common/constant.js';
import { getPackageJson, getVantConfig, LIB_DIR } from '../common/constant.js';
import { mergeCustomViteConfig } from '../common/index.js';
import { getViteConfigForPackage } from '../config/vite.package.js';
// generate entry file for nuxt
async function genEntryForSSR() {
const { name } = getVantConfig();
const cjsPath = join(LIB_DIR, 'ssr.js');
const mjsPath = join(LIB_DIR, 'ssr.mjs');
const cjsContent = `'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/${name}.cjs.min.js');
} else {
module.exports = require('./dist/${name}.cjs.js');
};
`;
const mjsContent = `export * from './index.js';\n`;
return Promise.all([
fse.outputFile(cjsPath, cjsContent),
fse.outputFile(mjsPath, mjsContent),
]);
}
export async function compileBundles() {
const dependencies = getPackageJson().dependencies || {};
const externals = Object.keys(dependencies);
@ -39,4 +64,5 @@ export async function compileBundles() {
await Promise.all(
configs.map((config) => build(mergeCustomViteConfig(config)))
);
await genEntryForSSR();
}

@ -10,6 +10,10 @@
"jsdelivr": "lib/vant.min.js",
"exports": {
".": {
"node": {
"import": "./lib/ssr.mjs",
"require": "./lib/ssr.js"
},
"import": "./lib/vant.es.js",
"require": "./lib/vant.cjs.js",
"types": "./lib/index.d.ts"