mais ajustes de build
This commit is contained in:
parent
9a332853b6
commit
889148eb42
3 changed files with 42 additions and 23 deletions
2
dist/index.mjs
vendored
Normal file
2
dist/index.mjs
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "p-comuns",
|
"name": "p-comuns",
|
||||||
"version": "0.252.0",
|
"version": "0.254.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
"module": "./dist-front/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -7,65 +7,82 @@ import path from 'node:path'
|
||||||
const pkgPath = path.resolve('package.json')
|
const pkgPath = path.resolve('package.json')
|
||||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
||||||
|
|
||||||
// Define os campos ao estilo “dayjs-like”: 1 entry CJS + 1 bundle global
|
// Agora vamos de Day.js “turbinado”: CJS + ESM + IIFE
|
||||||
const nextPkg = {
|
const nextPkg = {
|
||||||
...pkg,
|
...pkg,
|
||||||
main: 'dist/index.cjs', // Node / SSR (require)
|
main: 'dist/index.cjs', // Node / SSR (require)
|
||||||
|
module: 'dist/index.mjs', // Bundlers ESM
|
||||||
types: 'dist/index.d.ts', // Tipos
|
types: 'dist/index.d.ts', // Tipos
|
||||||
// NÃO usar "module" aqui (muitos bundlers esperam ESM) — deixa sem.
|
|
||||||
browser: 'dist/index.global.js', // Browser sem bundler (<script>)
|
browser: 'dist/index.global.js', // Browser sem bundler (<script>)
|
||||||
unpkg: 'dist/index.global.js', // CDN unpkg
|
unpkg: 'dist/index.global.js',
|
||||||
jsdelivr: 'dist/index.global.js', // CDN jsDelivr
|
jsdelivr: 'dist/index.global.js',
|
||||||
// Remove conflitos:
|
// Remove campos que atrapalham o resolver:
|
||||||
type: undefined as unknown as string,
|
type: undefined as unknown as string,
|
||||||
exports: undefined as unknown as Record<string, unknown>,
|
exports: undefined as unknown as Record<string, unknown>,
|
||||||
}
|
}
|
||||||
// Remove chaves undefined de fato
|
// remove chaves undefined
|
||||||
Object.keys(nextPkg).forEach((k) => {
|
for (const k of Object.keys(nextPkg)) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (nextPkg[k] === undefined) delete (nextPkg as any)[k]
|
if (nextPkg[k] === undefined) delete (nextPkg as any)[k]
|
||||||
})
|
}
|
||||||
fs.writeFileSync(pkgPath, JSON.stringify(nextPkg, null, 2) + '\n')
|
fs.writeFileSync(pkgPath, JSON.stringify(nextPkg, null, 2) + '\n')
|
||||||
|
|
||||||
// --- 1) Externals automáticos (não embutir deps/peerDeps) ---
|
// --- 1) Externals automáticos ---
|
||||||
const external = [
|
const external = [
|
||||||
...Object.keys(pkg.dependencies ?? {}),
|
...Object.keys(pkg.dependencies ?? {}),
|
||||||
...Object.keys(pkg.peerDependencies ?? {}),
|
...Object.keys(pkg.peerDependencies ?? {}),
|
||||||
]
|
]
|
||||||
|
|
||||||
// --- 2) Configuração tsup: CJS + IIFE (global) ---
|
// --- 2) Config tsup: CJS + ESM + IIFE ---
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
// 2.1) Bundle CJS para Node/SSR (gera dist/index.cjs + dist/index.d.ts)
|
// 2.1) CJS para Node/SSR (gera dist/index.cjs + dist/index.d.ts)
|
||||||
{
|
{
|
||||||
entry: { index: 'src/index.ts' },
|
entry: { index: 'src/index.ts' },
|
||||||
outDir: 'dist',
|
outDir: 'dist',
|
||||||
format: ['cjs'],
|
format: ['cjs'],
|
||||||
dts: true, // tipos aqui (um só lugar)
|
dts: true, // emite tipos aqui
|
||||||
platform: 'neutral', // evita polyfills de node
|
platform: 'neutral',
|
||||||
target: 'es2018',
|
target: 'es2018',
|
||||||
treeshake: true,
|
treeshake: true,
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
minify: true,
|
minify: true,
|
||||||
clean: true, // limpa dist apenas nesta job
|
clean: true, // limpa dist nesta job
|
||||||
external,
|
external,
|
||||||
skipNodeModulesBundle: true,
|
skipNodeModulesBundle: true,
|
||||||
outExtension: () => ({ js: '.cjs' }),
|
outExtension: () => ({ js: '.cjs' }),
|
||||||
},
|
},
|
||||||
|
|
||||||
// 2.2) Bundle global para browser (IIFE) → dist/index.global.js
|
// 2.2) ESM para bundlers (gera dist/index.mjs)
|
||||||
{
|
{
|
||||||
entry: { index: 'src/index.ts' },
|
entry: { index: 'src/index.ts' },
|
||||||
outDir: 'dist',
|
outDir: 'dist',
|
||||||
format: ['iife'],
|
format: ['esm'],
|
||||||
dts: false, // tipos já emitidos na primeira
|
dts: false, // tipos já emitidos
|
||||||
platform: 'browser',
|
platform: 'neutral',
|
||||||
target: 'es2015',
|
target: 'es2018',
|
||||||
globalName: 'PComuns', // expõe window.PComuns
|
|
||||||
treeshake: true,
|
treeshake: true,
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
minify: true,
|
minify: true,
|
||||||
clean: false,
|
clean: false,
|
||||||
external, // mantém deps externas se houver
|
external,
|
||||||
|
skipNodeModulesBundle: true,
|
||||||
|
outExtension: () => ({ js: '.mjs' }),
|
||||||
|
},
|
||||||
|
|
||||||
|
// 2.3) IIFE global para <script> (gera dist/index.global.js)
|
||||||
|
{
|
||||||
|
entry: { index: 'src/index.ts' },
|
||||||
|
outDir: 'dist',
|
||||||
|
format: ['iife'],
|
||||||
|
dts: false,
|
||||||
|
platform: 'browser',
|
||||||
|
target: 'es2015',
|
||||||
|
globalName: 'PComuns', // window.PComuns
|
||||||
|
treeshake: true,
|
||||||
|
sourcemap: false,
|
||||||
|
minify: true,
|
||||||
|
clean: false,
|
||||||
|
external,
|
||||||
skipNodeModulesBundle: true,
|
skipNodeModulesBundle: true,
|
||||||
outExtension: () => ({ js: '.global.js' }),
|
outExtension: () => ({ js: '.global.js' }),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue