This repository was archived by the owner on Mar 17, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -603,6 +603,72 @@ Result:
603
603
path/to/file.png? e43b20c069c4a01867c31e98cbce33c9
604
604
```
605
605
606
+ ---
607
+
608
+ ** main.js**
609
+
610
+ ``` js
611
+ const namespace = process .env .NAMESPACE ;
612
+ const assetPrefixForNamespace = (namespace ) => {
613
+ switch (namespace) {
614
+ case ' prod' :
615
+ return ' https://cache.myserver.net/web' ;
616
+ case ' uat' :
617
+ return ' https://cache-uat.myserver.net/web' ;
618
+ case ' st' :
619
+ return ' https://cache-st.myserver.net/web' ;
620
+ case ' dev' :
621
+ return ' https://cache-dev.myserver.net/web' ;
622
+ default :
623
+ return ' ' ;
624
+ }
625
+ };
626
+ __webpack_public_path__ = ` ${ assetPrefixForNamespace (namespace)} /` ;
627
+ ```
628
+
629
+ ** file.js**
630
+
631
+ ``` js
632
+ import png from ' ./image.png' ;
633
+ ```
634
+
635
+ ** webpack.config.js**
636
+
637
+ ``` js
638
+ module .exports = {
639
+ module: {
640
+ rules: [
641
+ {
642
+ test: / \. (png| jpg| gif)$ / ,
643
+ loader: ' file-loader' ,
644
+ options: {
645
+ context: ' ' ,
646
+ emitFile: true ,
647
+ name: ' [name].[hash].[ext]' ,
648
+ publicPath: ' static/assets/' ,
649
+ postTransformPublicPath : (p ) => ` __webpack_public_path__ + ${ p} ` ,
650
+ outputPath: ' static/assets/' ,
651
+ },
652
+ },
653
+ ],
654
+ },
655
+ };
656
+ ```
657
+
658
+ Result when run with ` NAMESPACE=prod ` env variable:
659
+
660
+ ``` bash
661
+ # result
662
+ https://cache.myserver.net/web/static/assets/image.somehash.png
663
+ ```
664
+
665
+ Result when run with ` NAMESPACE=dev ` env variable:
666
+
667
+ ``` bash
668
+ # result
669
+ https://cache-dev.myserver.net/web/static/assets/image.somehash.png
670
+ ```
671
+
606
672
## Contributing
607
673
608
674
Please take a moment to read our contributing guidelines if you haven't yet done so.
You can’t perform that action at this time.
0 commit comments