File tree 2 files changed +39
-5
lines changed
packages/webchannel-wrapper
2 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,22 @@ const commonjs = require('@rollup/plugin-commonjs');
26
26
const rollupSourcemaps = require ( 'rollup-plugin-sourcemaps' ) ;
27
27
const typescriptPlugin = require ( 'rollup-plugin-typescript2' ) ;
28
28
const typescript = require ( 'typescript' ) ;
29
+ const pkg = require ( './package.json' ) ;
30
+
31
+ // Copied from "../../scripts/build/rollup_emit_module_package_file" which is ESM
32
+ // and would require converting this file to MJS to use
33
+ function emitModulePackageFile ( ) {
34
+ return {
35
+ generateBundle ( ) {
36
+ this . emitFile ( {
37
+ fileName : 'package.json' ,
38
+ source : `{"type":"module"}` ,
39
+ type : 'asset'
40
+ } ) ;
41
+ } ,
42
+ name : 'emit-module-package-file'
43
+ } ;
44
+ }
29
45
30
46
// The optimization level for the JS compiler.
31
47
// Valid levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.
@@ -114,13 +130,31 @@ function createRollupTask({
114
130
} )
115
131
) ;
116
132
}
133
+ if ( format === 'es' ) {
134
+ plugins . push (
135
+ emitModulePackageFile ( )
136
+ ) ;
137
+ }
117
138
const inputOptions = {
118
139
input : inputPath ,
119
140
plugins
120
141
} ;
121
142
143
+ let outputFilename ;
144
+ if ( format === 'es' ) {
145
+ if ( compileToES5 ) {
146
+ // ESM5
147
+ outputFilename = pkg . esm5 ;
148
+ } else {
149
+ // ESM2017
150
+ outputFilename = pkg . module ;
151
+ }
152
+ } else {
153
+ // CJS
154
+ outputFilename = pkg . main ;
155
+ }
122
156
const outputOptions = {
123
- file : `dist/index ${ outputExtension ? '.' : '' } ${ outputExtension } .js` ,
157
+ file : outputFilename ,
124
158
format,
125
159
sourcemap : true ,
126
160
// Prevents warning when compiling CJS that there are named and default exports together.
Original file line number Diff line number Diff line change 4
4
"description" : " A wrapper of the webchannel packages from closure-library for use outside of a closure compiled application" ,
5
5
"author" :
" Firebase <[email protected] > (https://firebase.google.com/)" ,
6
6
"main" : " dist/index.js" ,
7
- "module" : " dist/index.esm2017.js" ,
8
- "esm5" : " dist/index.esm.js" ,
7
+ "module" : " dist/esm/ index.esm2017.js" ,
8
+ "esm5" : " dist/esm/ index.esm.js" ,
9
9
"exports" : {
10
10
"." : {
11
11
"types" : " ./src/index.d.ts" ,
12
12
"require" : " ./dist/index.js" ,
13
- "esm5" : " ./dist/index.esm.js" ,
14
- "default" : " ./dist/index.esm2017.js"
13
+ "esm5" : " ./dist/esm/ index.esm.js" ,
14
+ "default" : " ./dist/esm/ index.esm2017.js"
15
15
},
16
16
"./package.json" : " ./package.json"
17
17
},
You can’t perform that action at this time.
0 commit comments