File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -29,4 +29,19 @@ export default [
29
29
} ,
30
30
} ) ,
31
31
) ,
32
+ ...makeNPMConfigVariants (
33
+ makeBaseNPMConfig ( {
34
+ entrypoints : [ 'src/config/prefixLoader.ts' ] ,
35
+
36
+ packageSpecificConfig : {
37
+ output : {
38
+ // make it so Rollup calms down about the fact that we're doing `export { loader as default }`
39
+ exports : 'default' ,
40
+
41
+ // preserve the original file structure (i.e., so that everything is still relative to `src`)
42
+ entryFileNames : 'config/[name].js' ,
43
+ } ,
44
+ } ,
45
+ } ) ,
46
+ ) ,
32
47
] ;
Original file line number Diff line number Diff line change
1
+ import * as fs from 'fs' ;
2
+ import * as path from 'path' ;
3
+
4
+ // TODO Use real webpack types (different for webpack 4 and 5?)
5
+ type LoaderThis = {
6
+ getOptions : ( ) => {
7
+ distDir : string ;
8
+ } ;
9
+ } ;
10
+
11
+ /**
12
+ * Inject templated code into the beginning of a module.
13
+ */
14
+ function prefixLoader ( this : LoaderThis , userCode : string ) : string {
15
+ const { distDir } = this . getOptions ( ) ;
16
+
17
+ const templatePath = path . resolve ( __dirname , 'prefixLoaderTemplate.js' ) ;
18
+ let templateCode = fs . readFileSync ( templatePath ) . toString ( ) ;
19
+
20
+ // Fill in the placeholder
21
+ templateCode = templateCode . replace ( '__DIST_DIR__' , distDir ) ;
22
+
23
+ return `${ templateCode } \n${ userCode } ` ;
24
+ }
25
+
26
+ export { prefixLoader as default } ;
You can’t perform that action at this time.
0 commit comments