Create Virtual Uri plugin
A plugin to create a Virtual URI mapping configuration file in a light module. The file is created in the virtualUriMappings
directory in the module. The directory is created by the command if it doesn’t exist yet.
Package name |
|
Repository link |
|
Latest version |
|
Changelog link |
|
Prototypes available |
|
Installing
The plugin doesn’t come pre-installed with Magnolia CLI.
You must add it to the mgnl.config.js
project file.
The plugin is installed automatically by the Jumpstart plugin if it is defined in a project template. |
Usage
Options
Form (short and long) | Description |
---|---|
|
Sets the pattern to match in the requested uri. By default, uses an empty string. |
|
Maps the request to a concrete uri. By default, uses an empty string. The following action prefixes are supported:
|
|
Sets a light module for the virtual uri mapping.
By default, uses the directory specified in the |
|
The path to a custom prototype templates directory as the prototype source to create a mapping. |
|
A prototype to create a virtual uri mapping. |
|
Displays the version. |
|
Displays help information. |
Create mapping examples
In the following examples, assume that the mgnl.config.js
file looks like this:
import CreateVirtualUriPlugin from "@magnolia/cli-create-virtual-uri-plugin";
export default {
plugins: [
new CreateVirtualUriPlugin()
]
};
For more information, see Configuring plugins.
Based on the _default prototype
npm run mgnl -- create-virtual-uri "my-vu"
This command creates a new virtual URI mapping called my-vu
based on the _default
prototype.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new virtual URI mapping will be created.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
With a fromUri
value
npm run mgnl -- create-virtual-uri "my-vu" --from "/foo"
This command creates a new virtual URI mapping called my-vu
based on the _default
prototype, with /foo
as the value for the fromUri
property.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new virtual URI mapping will be created.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
With a toUri
value
npm run mgnl -- create-virtual-uri "my-vu" --to "forward:/bar"
This command creates a new virtual URI mapping called my-vu
based on the _default
prototype, with forward:/bar
as the value for the toUri
property.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new virtual URI mapping will be created.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
In a specific light module
npm run mgnl -- create-virtual-uri "my-vu" --light-module "my-lm"
This command creates a new virtual URI mapping called my-vu
based on the _default
prototype in the my-lm
light module.
The plugin will prompt you to choose a directory containing all light modules.
If the my-lm
light module doesn’t exist yet in the light modules directory, the plugin will prompt you to select another one.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
Using a specific prototype
npm run mgnl -- create-virtual-uri "my-vu" --prototype "regexp"
This command creates a new virtual URI mapping called my-vu
based on the regexp
prototype.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new virtual URI will be created.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
prototype
-
Using a prototype from a custom prototypes directory
npm run mgnl -- create-virtual-uri "my-vu" --prototype-dir "/path/to/custom-prototypes-dir/virtual-uri"
This command creates a new virtual URI mapping called my-vu
based on the _default
prototype from /path/to/custom-prototypes-dir/virtual-uri
.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new virtual URI will be created.
-
Choose a prototype if the
_default
prototype isn’t present in the custom prototypes directory.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
prototypeDir
-
prototype
-
The structure of the custom prototypes directory can be:
To use the custom
|
Configuration
You can set the following properties in mgnl.config.js
to predefine the plugin’s behavior.
Global properties
Property name | Description |
---|---|
|
The path to a directory containing all light modules. |
|
The name of a light module where the virtual uri will be created. Alternative forms: |
Plugin properties
Property name | Description |
---|---|
|
The name of a light module where the virtual uri will be created. Alternative forms: |
|
The path to a custom prototypes directory. Alternative forms: |
|
The name of a prototype. Alternative forms: |
For more information, see Configuring plugins.