@node-sitecore/vue-cli
Add support configuration for Vue-cli stack.
Installation
To begin, generate your front-end project with Vue-cli and run the generator:
$ vue create .Select theses recommanded options:
Babel,
Vuex (optional),
CSS Pre-processor (Sass),
Linter (ESlint),
Unit test (Jest)
Then install @node-sitecore/cli-plugin-vue with npm or yarn:
$ npm install @node-sitecore/cli-plugin-vueCli
This package add a new command:
Usage: nsc vue <build|check> [options]
Options:
-V, --version output the version number
--configPath <path> Path to .nscrc file
--currentWebsite <code> Default current website to compile source
-p, --pattern <cmd> Glob pattern to list project
-l, --list <cmd> Website code list (EU,FR,etc)
-e, --exclude <cmd> Exclude Website code list (Common,etc)
-h, --help output usage information
Example:
nsc vue build // build only the default currentWebsite
nsc vue build --list EU,FR
nsc vue build --pattern "scr/Project/*" --exclude Hotfix,Common
nsc check // Check if entries exists for a given currentWebsiteBuild command is a shortcut to compile multiple Sitecore Projects. It's an equivalent of:
Configuration
Now, edit the vue.config.js and copy this configuration:
If you use Jest, edit jest.config.js also:
Finally, edit your .nscrc file and add Vue-cli configuration:
A project example is available on this repository https://github.com/NodeSitecore/sitecore-vue-boilerplate.
Options
scssMixinsPath: Add the scss file which include all of your mixins/variables should be shared with Vue Component.outputDir: Output directory where the source will be compiled.baseUrl: Set the base url for the different profile.entries: Configure the bundle compilation strategies (See Define entries section).alias: Set alias list for webpack (See Define alias section).
Getters
Configuration fields
Key
Default value
Tags
Description
vueCli
{...}
Vue-cli, Vue
Return the configuration dedicated to Vue-cli.
entries
[...]
Vue-cli, Vue
Entries list which will be compilied by webpack
Define entries
VueCli configuration accept multiple entries files. Webpack will create different bundles according to your configuration. Also, each entry can be configured by environment profile (production or development).
Here three possible scenario (production, development and all profile):
This example generate two bundles
bundle.jsandadmin.jsbutbundle.js.
Entry options:
mode: NODE_ENV profile. Indicates for which profile the bundle should be generatedname: Bundle name generated by webpackextractVendors: Compile NPM module in a separated file (vendors.bundle.js). By defaulttrue.paths: List of files you want to compile for the bundle.
Define new alias
Webpack provide a alias mechanism to facilitate javascript module import. By default, this package provide these following alias:
Alias can be used in you Vue and Javascript file like that:
PWA
Vue-cli provide an extension to manage Progressive web application with webpack. To generate multiple serviceWorker per project/site, you have to configure PWA options in your vue.config.js and edit the registerServiveWorker.js generated by Vue-cli.
In vue.config.js add this configuration:
Then in the registerServiceWorker.js:
And finally, edit your nuspec file and add this entry:
Switch Project/Site
Sitecore allow to have multiple site workspace like EU, GR, etc... the npm run develop compile only one localization to preview your code in Fractal for a given project. To change the default currentWebsite without change the .nscrc default configuration, create a new file .dev.nscrc and copy this code:
Change the code according to the project code you want to preview in fractal then run
npm run develop.
Last updated