Created
August 10, 2017 16:38
-
-
Save J2D2Development/6f520dd991a6a33c1152aabcdf346790 to your computer and use it in GitHub Desktop.
Replace es6 with umd bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { readFile, writeFile } = require('fs'); | |
const { join } = require('path'); | |
readFile(join(__dirname, '../dist-server/main.bundle.js'), 'utf-8', (err, data) => { | |
if(err) { return console.log('Error reading file:', err); } | |
const ssrPageScrollBundle = 'ng2-page-scroll/bundles/ng2-page-scroll.umd.js' | |
const newCode = data.replace('ng2-page-scroll', ssrPageScrollBundle) | |
.replace('ng2-page-scroll/src/ng2-page-scroll.module', ssrPageScrollBundle) | |
.replace('ng2-page-scroll/src/ng2-page-scroll.service', ssrPageScrollBundle) | |
.replace('ng2-page-scroll/src/ng2-page-scroll.directive', ssrPageScrollBundle); | |
writeFile('./dist-server/main.bundle.js', newCode, 'utf-8', err => { | |
if(err) { return console.log('Error writing file:', err); } | |
console.log('Done editing main.bundle.js to use amd bundles for external libraries'); | |
}); | |
}); |
Holee cow, this solved it for me with mobx-angular and angular-tree-component! Some RegExp can save you from the pain of finding all the module names one lib may have:
.replace(/require\(\"angular\-tree\-component[^\"]*\"/g, 'require("angular-tree-component/dist/angular-tree-component.umd.js"')
I have the same Issue with ng2-page-scroll and SSR, Where do i add this script?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. It worked for
ng2-page-scroll
but I got stucked on the next library :) I guess I will wait with SSR until such issues are resolved.