1
1
// @ts -check
2
- import { dirname , resolve } from 'node:path'
2
+ import { dirname , parse , resolve } from 'node:path'
3
3
import { fileURLToPath } from 'node:url'
4
4
import { readFileSync } from 'node:fs'
5
5
import ts from 'rollup-plugin-typescript2'
@@ -23,7 +23,6 @@ const packageDir = resolve(packagesDir, process.env.TARGET)
23
23
const pkg = JSON . parse (
24
24
readFileSync ( resolve ( packageDir , `package.json` ) , 'utf-8' )
25
25
)
26
- const name = pkg . name
27
26
28
27
function getAuthors ( pkg ) {
29
28
const { contributors, author } = pkg
@@ -68,18 +67,10 @@ const outputConfigs = {
68
67
} ,
69
68
}
70
69
71
- const packageBuilds = Object . keys ( outputConfigs )
72
- const packageConfigs = packageBuilds . map ( ( format ) =>
73
- createConfig ( format , outputConfigs [ format ] )
74
- )
75
-
76
- // only add the production ready if we are bundling the options
77
- packageBuilds . forEach ( ( buildName ) => {
78
- if ( buildName === 'cjs' ) {
79
- packageConfigs . push ( createProductionConfig ( buildName ) )
80
- } else if ( buildName === 'global' || buildName === 'browser' ) {
81
- packageConfigs . push ( createMinifiedConfig ( buildName ) )
82
- }
70
+ const packageConfigs = [ ]
71
+ Object . entries ( outputConfigs ) . forEach ( ( [ buildName , output ] ) => {
72
+ packageConfigs . push ( createConfig ( buildName , output ) )
73
+ packageConfigs . push ( createProductionConfig ( buildName , output ) )
83
74
} )
84
75
85
76
export default packageConfigs
@@ -99,7 +90,7 @@ function createConfig(buildName, output, plugins = []) {
99
90
100
91
const isProductionBuild = / \. p r o d \. [ c m ] ? j s $ / . test ( output . file )
101
92
const isGlobalBuild = buildName === 'global'
102
- const isRawESMBuild = buildName . includes ( 'browser' )
93
+ const isRawESMBuild = buildName === 'browser'
103
94
const isNodeBuild = buildName === 'cjs'
104
95
const isBundlerESMBuild = buildName === 'browser' || buildName === 'mjs'
105
96
@@ -126,7 +117,7 @@ function createConfig(buildName, output, plugins = []) {
126
117
hasTSChecked = true
127
118
128
119
const external = [ 'vue' ]
129
- if ( buildName !== 'browser-prod' ) external . push ( '@vue/devtools-api' )
120
+ if ( ! isProductionBuild ) external . push ( '@vue/devtools-api' )
130
121
131
122
const nodePlugins = [ nodeResolve ( ) , commonjs ( ) ]
132
123
@@ -209,25 +200,17 @@ function createReplacePlugin(
209
200
} )
210
201
}
211
202
212
- function createProductionConfig ( format ) {
213
- const extension = format === 'cjs' ? 'cjs' : 'js'
214
- const descriptor = format === 'cjs' ? '' : `.${ format } `
215
- return createConfig ( format , {
216
- file : `dist/${ name } ${ descriptor } .prod.${ extension } ` ,
217
- format : outputConfigs [ format ] . format ,
218
- } )
219
- }
220
-
221
- function createMinifiedConfig ( format ) {
203
+ function createProductionConfig ( buildName , output ) {
204
+ const parsedPath = parse ( output . file )
222
205
return createConfig (
223
- format === 'browser' ? 'browser-prod' : format ,
206
+ buildName ,
224
207
{
225
- file : `dist/ ${ name } .${ format === 'browser' ? 'esm-browser' : format === 'global' ? 'iife' : format } .prod.js` ,
226
- format : outputConfigs [ format ] . format ,
208
+ file : resolve ( parsedPath . dir , ` ${ parsedPath . name } .prod ${ parsedPath . ext } ` ) ,
209
+ format : output . format ,
227
210
} ,
228
211
[
229
212
terser ( {
230
- module : / ^ e s m / . test ( format ) ,
213
+ module : output . format === 'es' ,
231
214
compress : {
232
215
ecma : 2015 ,
233
216
pure_getters : true ,
0 commit comments