@@ -32,21 +32,21 @@ export function sizzlePlugin(opts: BuildOptions): Plugin {
32
32
if ( id !== 'sizzle' ) {
33
33
return null ;
34
34
}
35
- const f = opts . isProd ? 'sizzle.min.js' : 'sizzle.js' ;
36
- const sizzlePath = join ( opts . nodeModulesDir , 'sizzle' , 'dist' , f ) ;
37
- const sizzleContent = await fs . readFile ( sizzlePath , 'utf8' ) ;
38
- return getSizzleBundle ( opts , sizzleContent ) ;
35
+ return getSizzleBundle ( opts ) ;
39
36
} ,
40
37
} ;
41
38
}
42
39
43
40
/**
44
41
* Creates a sizzle bundle to inline
45
42
* @param opts the options being used during a build of the Stencil compiler
46
- * @param content the sizzle source contents
47
43
* @returns a modified version of sizzle, wrapped in an immediately invoked function expression (IIFE)
48
44
*/
49
- function getSizzleBundle ( opts : BuildOptions , content : string ) : string {
45
+ async function getSizzleBundle ( opts : BuildOptions ) : Promise < string > {
46
+ const f = opts . isProd ? 'sizzle.min.js' : 'sizzle.js' ;
47
+ const sizzlePath = join ( opts . nodeModulesDir , 'sizzle' , 'dist' , f ) ;
48
+ const sizzleContent = await fs . readFile ( sizzlePath , 'utf8' ) ;
49
+
50
50
return `// Sizzle ${ opts . sizzleVersion }
51
51
export default (function() {
52
52
const window = {
@@ -63,18 +63,22 @@ const window = {
63
63
};
64
64
const module = { exports: {} };
65
65
66
- ${ content }
66
+ ${ sizzleContent }
67
67
68
68
return module.exports;
69
69
})();
70
70
` ;
71
71
}
72
72
73
+ /**
74
+ * Write a file containing our patched version of Sizzle to a location on disk
75
+ * and return the path for that location
76
+ *
77
+ * @param opts the build options
78
+ * @returns a Promise wrapping the path where Sizzle can be found
79
+ */
73
80
export async function writeSizzleBundle ( opts : BuildOptions ) : Promise < string > {
74
- const f = opts . isProd ? 'sizzle.min.js' : 'sizzle.js' ;
75
- const sizzlePath = join ( opts . nodeModulesDir , 'sizzle' , 'dist' , f ) ;
76
- const sizzleContent = await fs . readFile ( sizzlePath , 'utf8' ) ;
77
- const patchedSizzle = getSizzleBundle ( opts , sizzleContent ) ;
81
+ const patchedSizzle = await getSizzleBundle ( opts ) ;
78
82
79
83
const fileName = `sizzle--bundle-cache${ opts . isProd ? '.min' : '' } .js` ;
80
84
const cacheFile = join ( opts . scriptsBuildDir , fileName ) ;
0 commit comments