7
7
nodeResolve,
8
8
} = require ( '@rollup/plugin-node-resolve' )
9
9
const replace = require ( '@rollup/plugin-replace' )
10
- const glob = require ( 'glob' )
11
10
const camelcase = require ( 'lodash.camelcase' )
12
11
const { terser} = require ( 'rollup-plugin-terser' )
13
12
const nodeBuiltIns = require ( 'rollup-plugin-node-builtins' )
@@ -21,7 +20,8 @@ const {
21
20
hasDep,
22
21
hasTypescript,
23
22
parseEnv,
24
- fromRoot,
23
+ getRollupInputs,
24
+ getRollupOutput,
25
25
uniq,
26
26
writeExtraEntry,
27
27
} = require ( '../utils' )
@@ -51,27 +51,6 @@ const deps = Object.keys(pkg.dependencies || {})
51
51
const peerDeps = Object . keys ( pkg . peerDependencies || { } )
52
52
const defaultExternal = umd ? peerDeps : deps . concat ( peerDeps )
53
53
54
- const input = glob . sync (
55
- fromRoot (
56
- process . env . BUILD_INPUT ||
57
- ( hasTypescript ? 'src/index.{js,ts,tsx}' : 'src/index.js' ) ,
58
- ) ,
59
- )
60
- const codeSplitting = input . length > 1
61
-
62
- if (
63
- codeSplitting &&
64
- uniq ( input . map ( single => path . basename ( single ) ) ) . length !== input . length
65
- ) {
66
- throw new Error (
67
- 'Filenames of code-splitted entries should be unique to get deterministic output filenames.' +
68
- `\nReceived those: ${ input } .` ,
69
- )
70
- }
71
-
72
- const filenameSuffix = process . env . BUILD_FILENAME_SUFFIX || ''
73
- const filenamePrefix =
74
- process . env . BUILD_FILENAME_PREFIX || ( isPreact ? 'preact/' : '' )
75
54
const globals = parseEnv (
76
55
'BUILD_GLOBALS' ,
77
56
isPreact ? Object . assign ( defaultGlobals , { preact : 'preact' } ) : defaultGlobals ,
@@ -102,30 +81,6 @@ function externalPredicate(id) {
102
81
return isDep || ( ! isRelative && ! path . isAbsolute ( id ) ) || isNodeModule
103
82
}
104
83
105
- const filename = [
106
- pkg . name ,
107
- filenameSuffix ,
108
- `.${ format } ` ,
109
- minify ? '.min' : null ,
110
- '.js' ,
111
- ]
112
- . filter ( Boolean )
113
- . join ( '' )
114
-
115
- const dirpath = path . join ( ...[ filenamePrefix , 'dist' ] . filter ( Boolean ) )
116
-
117
- const output = [
118
- {
119
- name,
120
- ...( codeSplitting
121
- ? { dir : path . join ( dirpath , format ) }
122
- : { file : path . join ( dirpath , filename ) } ) ,
123
- format : esm ? 'es' : format ,
124
- exports : esm ? 'named' : 'auto' ,
125
- globals,
126
- } ,
127
- ]
128
-
129
84
const useBuiltinConfig =
130
85
! hasFile ( '.babelrc' ) &&
131
86
! hasFile ( '.babelrc.js' ) &&
@@ -150,6 +105,33 @@ const extensions = hasTypescript
150
105
? [ ...nodeResolveDefaults . extensions , '.ts' , '.tsx' ]
151
106
: nodeResolveDefaults . extensions
152
107
108
+ const input = getRollupInputs ( )
109
+ const codeSplitting = input . length > 1
110
+
111
+ if (
112
+ codeSplitting &&
113
+ uniq ( input . map ( single => path . basename ( single ) ) ) . length !== input . length
114
+ ) {
115
+ throw new Error (
116
+ 'Filenames of code-splitted entries should be unique to get deterministic output filenames.' +
117
+ `\nReceived those: ${ input } .` ,
118
+ )
119
+ }
120
+
121
+ const { dirpath, filename} = getRollupOutput ( )
122
+
123
+ const output = [
124
+ {
125
+ name,
126
+ ...( codeSplitting
127
+ ? { dir : path . join ( dirpath , format ) }
128
+ : { file : path . join ( dirpath , filename ) } ) ,
129
+ format : esm ? 'es' : format ,
130
+ exports : esm ? 'named' : 'auto' ,
131
+ globals,
132
+ } ,
133
+ ]
134
+
153
135
module . exports = {
154
136
input : codeSplitting ? input : input [ 0 ] ,
155
137
output,
0 commit comments