Closed wawyed closed 7 years ago
Is it possible to get an answer on this please?
I think it sounds like the problem is your custom fetch function is stopping SystemJS builder from being able to "fetch" the text plugin itself? If so a simple exception in the fetch logic might work then?
@guybedford The problem is that SystemJS builder is not trying to use the fetch function to fetch the loader plugin.
Ah right, so the fetch hook is applying only for the compiled source and not the plugin itself?
In that case, perhaps just set a map config for the plugin:
builder.bundle('app/main', {
fetch: ...,
config: {
map: {
text: 'correct/location.js'
}
}
}
Exactly.
I already tried that, the problem is that the path to the plugin is not relative to the folder and doing ../ doesn't work.
@wawyed it does sound like a path forward though, can you elaborate on those issues? Also you can try using paths
instead of map
as well.
My folder structure is as follows:
-root/
-src/
-main.ts
-systemjs.config.js
//all the other files live here, including the text/html files i want to import.
-node_modules/
When I run my dev task, the server has the following structure:
-dev/
-main.js
-systemjs.config.js
-shared/
-libraries/
-systemjs-plugin-text/
-text.js
// any other node_modules that I need go here
Now, when I want to build my distribution bundle I don't want to have to copy files to a temp directory so I use the fetch function to override where systemjs is expecting the files. I do this for two things:
This works fine until I introduce the text loader. SystemJS builder seems to ignore the fetch function for the plugin and try to load for the location specified in systemjs.config.js. Since anything specified in that file has to be relative to the location of systemjs.config.js I have no way to change the config to change the location to node_modules/ (there is no node_modules inside src).
I'm asking for either a way to override the location in gulp/node or a way to provide the loader to the builder or make loaders go to the fetch function to load them first..
Hope this info helps in order to understand my issue better.
Good news! I manage to do it.
I added the full path in the paths config for dev:
(function(System) {
'use strict';
System.config({
map: {
'@angular/core': 'libraries:@angular/core/bundles/core.umd.js',
'@angular/common': 'libraries:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'libraries:@angular/compiler/bundles/compiler.umd.js',
'@angular/upgrade': 'libraries:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/platform-browser': 'libraries:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/src/facade/browser': 'libraries:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'libraries:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'libraries:@angular/http/bundles/http.umd.js',
'@angular/forms': 'libraries:@angular/forms/bundles/forms.umd.js',
rxjs: 'libraries:rxjs',
lodash: 'libraries:lodash',
moment: 'libraries:moment',
jquery: 'libraries:jquery/dist',
'element-resize-detector': 'libraries:element-resize-detector/dist'
},
packages: {
app: {
main: 'main',
defaultExtension: 'js'
},
rxjs: {
main: 'Rx',
defaultExtension: 'js'
},
lodash: {
main: 'lodash',
defaultExtension: 'js'
},
moment: {
main: 'moment',
defaultExtension: 'js'
},
jquery: {
main: 'jquery',
defaultExtension: 'js'
},
'element-resize-detector': {
main: 'element-resize-detector',
defaultExtension: 'js'
}
},
paths: {
'libraries:': 'shared/libraries/',
'textLoader:': 'shared/libraries/systemjs-plugin-text/text.js'
},
meta: {
'*.html': {
loader: 'textLoader'
}
}
});
})(System);
And for distribution bundle I modified and make it absolute by using file:/// like this:
builder.config({
paths: {
'libraries:': 'shared/libraries/',
'textLoader': 'file:///' + path.resolve('./node_modules/systemjs-plugin-text/text.js')
},
defaultJSExtensions: true // Doesn't add the default extension https://github.com/systemjs/builder/issues/728
});
@wawyed glad to hear it is resolved 😀.
I currently have this configuration:
In development I create a libraries folder with the dependencies I need and this works fine. When I have to build the bundle for distribution I created my own fetch function so that I don't need to copy dependencies since I'm using gulp. This looks something like this:
This was working fine until I decided to add the text loader. Now I'm getting this error when trying to bundle:
My question is, is there any way I can make the text loader work either via defining my own loader which just points to systemjs-plugin-text or via any other mechanism?
Thanks.