atularen / ngx-monaco-editor

Monaco Editor component for Angular 2 and Above
https://www.npmjs.com/package/ngx-monaco-editor
MIT License
428 stars 155 forks source link

Support base-href option #63

Open yowari opened 6 years ago

yowari commented 6 years ago

ngx-monaco-editor does not take into account base-href option when building Angular app. For now, we have to configure baseUrl when importing the module. I think the component should be able to get the baseHref and use it as default path. Meaning, we should perhaps have by default ${baseHref}/assets instead of /assets. https://github.com/atularen/ngx-monaco-editor/blob/2ffca32ec03de436ef7ea2fa6d901eba7e638390/src/platform/editor/base-editor.ts#L40 To do so, we first have to inject the baseHref, which is not a simple thing to do 😛 (at least elegantly). My idea is to first extract a service from the BaseEditor class and then manage to inject the baseHref. What do you think? ps: For instance, I use a hacky way to do this behaviour without altering the code in my project https://github.com/yowari/code-challenger/blob/master/src/app/shared/shared.module.ts btw: first time trying to contribute to a GitHub project so please be kind :blush:

bboehm86 commented 6 years ago

I guess ./assets as default would be ok too 🤔

yowari commented 6 years ago

Well, if you don't provide --base-href option in ng build --prod, /assets will be used (default behaviour). This, for example, can help to set npm script to build Angular app for gh-pages and prod (exemple: for Docker) easily without changing code. The other ways is to set env variable for assets path or as i do in my project, retrieve the base-href path used. I already submitted a PR #64 . It not really a good solution but it works :confused:

crevan236 commented 6 years ago

I'm facing that problem too. Any walkaround?

OK, after i wrote that i read @yowari comment once again and i'll try that way. Thanks =)

gflegar commented 6 years ago

Seems that ./assets works too, like @bboehm86 suggested, though not sure why. I'm able to build for gh-pages by using the following import in AppModule:

MonacoEditorModule.forRoot({baseUrl: "./assets"})
pinktoadette commented 5 years ago

this doesn't work for me

crisz commented 5 years ago

Seems that ./assets works too, like @bboehm86 suggested, though not sure why. I'm able to build for gh-pages by using the following import in AppModule:

MonacoEditorModule.forRoot({baseUrl: "./assets"})

This worked perfectly for me. It should be quoted in the Readme.md in my opinion

OleksandrGavryshko commented 4 years ago

It's doesn't work for me too

maitrungduc1410 commented 1 year ago

it works fine for me, even with remote URL:

MonacoEditorModule.forRoot({
  baseUrl: 'http://localhost:53015/assets'
})