You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any URL can be loaded as a module with standard URL syntax:
任何符合标准语法的 URL 都可以被作为模块加载:
<scriptsrc="system.js"></script><script>// loads relative to the current page URLSystem.import('./local-module.js');// load from an absolute URL directlySystem.import('https://code.jquery.com/jquery.js');</script>
Any type of module format can be loaded and it will be detected automatically by SystemJS.
任何类型的模块格式都可以被 SystemJS 加载并自动检测。
##### File access from files
从文件中访问
Note that when running locally, ensure you are running from a local server or a browser with local XHR requests enabled. If not you will get an error message.
In Firefox this requires navigating to about:config, entering security.fileuri.strict_origin_policy in the filter box and toggling the option to false.
Module names of the above form are referred to as plain names and are always loaded baseURL-relative instead of
parentURL relative like one would expect with ordinary URLs.
Note we always run the System.config function instead of setting instance properties directly as this will set the correct normalized baseURL in the process.
The baseURL is very useful for providing an absolute reference URL for loading all modules, but we don't necessarily want to
have to locate every single shared dependency from within one folder.
Note that if using the defaultJSExtensions compatibility feature, plugins for resources with custom extensions will only work by using the package configurationdefaultExtension: false option to override this for specific packages.
Then configure a custom resource to be loaded via the plugin, we then use meta configuration:
配置一个自定义资源并通过插件加载,我们可以使用 meta 配置项:
System.config({// locate the plugin via map configuration// (alternatively have it in the baseURL)map: {text: '/path/to/text-plugin.js'},// use meta configuration to reference which modules// should use the plugin loadermeta: {'templates/*.html': {loader: 'text'}}});
Now any code that loads from [baseURL]/templates/*.html will use the text loader plugin and return the loaded content:
现在从 [baseURL]/templates/*.html 加载的任何代码将被使用 text 加载器指向的插件并返回加载后的内容。
Loading Modules
Any URL can be loaded as a module with standard URL syntax:
Any type of module format can be loaded and it will be detected automatically by SystemJS.
##### File access from files
Loading ES6
app/es6-file.js:
ES6 modules define named exports, provided as getters on a special immutable
Module
object.### Loader Configuration
Some of the standard configuration options and their use cases are described below.
For a reference see the Config API page.
baseURL
The baseURL provides a special mechanism for loading modules relative to a standard reference URL.
This can be useful for being able to refer to the same module from many different page URLs or environments:
Module names of the above form are referred to as plain names and are always loaded baseURL-relative instead of
parentURL relative like one would expect with ordinary URLs.
#### Map Config
The baseURL is very useful for providing an absolute reference URL for loading all modules, but we don't necessarily want to
have to locate every single shared dependency from within one folder.
Sometimes we want to load things from different places.
Map configuration is useful here to be able to specific exactly where to locate a given package:
Map configuration can also be used to map subpaths:
Map configuration is always applied before the baseURL rule in the loader.
### Plugin Loaders
Plugins handle alternative loading scenarios, including loading assets such as CSS or images, and providing custom transpilation scenarios.
Plugins can also inline into bundles or remain separate requests when using SystemJS Builder.
To create a custom plugin, see the documentation on creating plugins.
#### Basic Use
To use a plugin, set up the plugin itself as a standard module, either locating it in the baseURL or providing map configuration for it.
In this case, we're using the text plugin as an example.
Then configure a custom resource to be loaded via the plugin, we then use meta configuration:
Now any code that loads from
[baseURL]/templates/*.html
will use the text loader plugin and return the loaded content:app.js
When we build app.js, the text plugin will then automatically inline the templates into the bundle during the build.
#### Plugin Syntax
It is also possible to use syntax to load via plugins instead of configuration:
When no plugin is explicitly specified the extension is used as the plugin name itself.
#### 原文地址:https://github.com/systemjs/systemjs/blob/master/docs/overview.md
## Thanks
The text was updated successfully, but these errors were encountered: