vue-entry-loader
easywebpack Vue Entry Template, simplify Vue initialization without writing javascript file(.js
) init code, support client render and server side render.
Vue Initialization Template
When Wepback's entry configuration is directly a .vue
file, The following template code, webpack will be automatically merged with the Vue file.
Client Render Initialization Template
;// .vue file ;// ${codeSegment} dynamic template code template fileconst data = window__INITIAL_STATE__ || {};const context = state: data ;const hook = vmhook || Vuehook;if hook && hookrender hook;const store = typeof vmstore === 'function' ? vm : vmstore;const router = typeof vmrouter === 'function' ? vm : vmrouter;const options = store && router ? ...vm store router : ...vm data ;const app = options;app;
Server Side Render Initialization Template
;;// .vue file ;// ${codeSegment} dynamic template code template file { const store = typeof vmstore === 'function' ? vm : vmstore; const router = typeof vmrouter === 'function' ? vm : vmrouter; if store && router ; router; return { router; }; const VueApp = Vue; const hook = vmhook || Vuehook; if hook && hookrender hook; const instanceOptions = ...vm data: contextstate ; return instanceOptions;};
Usage
Vue Entry File
// ${root}/egg-vue-webpack-boilerplate/app/web/page/admin/home/home.vue;;;;;;; Vue;Vue; router store components: {} computed: {} hook : { const i18n = ; vmi18n = i18n; } {};
easywebpack Entry Config
moduleexports = entry: app: 'app/web/page/admin/home/home.vue' // The entry will use the vue-entry-loader, not need to write the Vue initialization code test: 'app/web/page/test/test.js' // The entry will not use the vue-entry-loader, you need to write the Vue initialization code ;
Feature
Dynamic Inject Template Code
;
-
Egg Project will inject the custom template code into the location above
${codeSegment}
when the fileapp/web/framework/entry/template.js
exists -
Non Egg Project will inject the custom template code into the location above
${codeSegment}
when the filesrc/framework/entry/template.js
exists -
The
entry/template.js
template file has the following constraints:- import path must be absolute path, you can use webpack alias set
- export default must return function, the argument is Vue
// import path must be absolute path, you can use webpack alias set; ; // must return function, the argument is Vue { Vue; Vue;}
Vue Entry File Initialization Hook Support
support hook.render
method for custom logic, such common component and logic initialization
hook : { const i18n = ; vmi18n = i18n; } computed: {} {};
Vue Entry File Initialization Dynamic Store and Router
dynamic create store, solve the server side render singleton problem
// store/index.js { const state = ...initState ; return state actions getters mutations ;}
- Dynamic Create Router
{ return mode: 'history' base: '/' routes: path: '/' component: Dashboard path: '*' import'../view/notfound.vue' ;}
- Vue Entry File Code
;; router // support Object and Function store // support Object and Function components: {} computed: {} {};