{"id":19990328,"url":"https://github.com/easy-team/vue-entry-loader","last_synced_at":"2025-12-30T08:23:29.026Z","repository":{"id":39917236,"uuid":"148770647","full_name":"easy-team/vue-entry-loader","owner":"easy-team","description":"Vue Entry Template Initialization Code for easywebapck","archived":false,"fork":false,"pushed_at":"2023-01-07T13:12:40.000Z","size":613,"stargazers_count":5,"open_issues_count":12,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-11T20:39:54.463Z","etag":null,"topics":["vue","vue-entry-template","webpack"],"latest_commit_sha":null,"homepage":"https://easyjs.cn","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/easy-team.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-14T10:00:11.000Z","updated_at":"2020-09-13T07:04:47.000Z","dependencies_parsed_at":"2023-02-07T06:07:01.064Z","dependency_job_id":null,"html_url":"https://github.com/easy-team/vue-entry-loader","commit_stats":null,"previous_names":["hubcarl/vue-entry-loader"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-team%2Fvue-entry-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-team%2Fvue-entry-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-team%2Fvue-entry-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/easy-team%2Fvue-entry-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/easy-team","download_url":"https://codeload.github.com/easy-team/vue-entry-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224391390,"owners_count":17303609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vue","vue-entry-template","webpack"],"created_at":"2024-11-13T04:51:08.835Z","updated_at":"2025-12-30T08:23:28.986Z","avatar_url":"https://github.com/easy-team.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# vue-entry-loader\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/vue-entry-loader.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/vue-entry-loader\n[travis-image]: https://img.shields.io/travis/hubcarl/vue-entry-loader.svg?style=flat-square\n[travis-url]: https://travis-ci.org/hubcarl/vue-entry-loader\n[codecov-image]: https://img.shields.io/codecov/c/github/hubcarl/vue-entry-loader.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/hubcarl/vue-entry-loader?branch=master\n[david-image]: https://img.shields.io/david/hubcarl/vue-entry-loader.svg?style=flat-square\n[david-url]: https://david-dm.org/hubcarl/vue-entry-loader\n[snyk-image]: https://snyk.io/test/npm/vue-entry-loader/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/vue-entry-loader\n[download-image]: https://img.shields.io/npm/dm/vue-entry-loader.svg?style=flat-square\n[download-url]: https://npmjs.org/package/vue-entry-loader\n\neasywebpack Vue Entry Template, simplify Vue initialization without writing javascript file(`.js`) init code, support client render and server side render.\n\n## Vue Initialization Template\n\n\nWhen Wepback's entry configuration is directly a `.vue` file, The following template code, webpack will be automatically merged with the Vue file.\n\n\n### Client Render Initialization Template\n\n```js\nimport Vue from 'vue';\n// .vue file \nimport vm from '${context.resourcePath}';\n// ${codeSegment} dynamic template code template file\nconst data = window.__INITIAL_STATE__ || {};\nconst context = { state: data };\nconst hook = vm.hook || Vue.hook;\nif (hook \u0026\u0026 hook.render) {\n  hook.render(context, vm);\n}\nconst store = typeof vm.store === 'function' ? vm.store(data) : vm.store;\nconst router = typeof vm.router === 'function' ? vm.router() : vm.router;\nconst options = store \u0026\u0026 router ? {\n  ...vm, \n  store,\n  router\n} : { ...vm, data };\nconst app = new Vue(options);\napp.$mount('#app');\n```\n\n\n### Server Side Render Initialization Template\n\n```js\nimport Vue from 'vue';\nimport { sync } from 'vuex-router-sync';\n// .vue file \nimport vm from '${context.resourcePath}';\n// ${codeSegment} dynamic template code template file\nexport default function(context) {\n  const store = typeof vm.store === 'function' ? vm.store(context.state) : vm.store;\n  const router = typeof vm.router === 'function' ? vm.router() : vm.router;\n  if (store \u0026\u0026 router) {\n    sync(store, router);\n    router.push(context.state.url);\n    return new Promise((resolve, reject) =\u003e {\n      router.onReady(() =\u003e {\n        const matchedComponents = router.getMatchedComponents();\n        if (!matchedComponents) {\n          return reject({ code: '404' });\n        }\n        return Promise.all(\n          matchedComponents.map(component =\u003e {\n            if (component.methods \u0026\u0026 component.methods.fetchApi) {\n              return component.methods.fetchApi(store);\n            }\n            return null;\n          })\n        ).then(() =\u003e {\n          context.state = { ...store.state, ...context.state };\n          const hook = vm.hook || Vue.hook;\n          if (hook \u0026\u0026 hook.render) {\n            hook.render(context, vm);\n          }\n          const instanceOptions = {\n            ...vm,\n            store,\n            router,\n          };\n          return resolve(new Vue(instanceOptions));\n        });\n      });\n    });\n  }\n  const VueApp = Vue.extend(vm);\n  const hook = vm.hook || Vue.hook;\n  if (hook \u0026\u0026 hook.render) {\n    hook.render(context, vm);\n  }\n  const instanceOptions = {\n    ...vm,\n    data: context.state\n  };\n  return new VueApp(instanceOptions);\n};\n```\n\n## Usage\n\n### Vue Entry File\n\n```js\n// ${root}/egg-vue-webpack-boilerplate/app/web/page/admin/home/home.vue\nimport Vue from 'vue';\nimport ElementUI from 'element-ui';\nimport VueI18n from 'vue-i18n';\nimport 'element-ui/lib/theme-chalk/index.css';\nimport createI18n from 'framework/i18n/admin';\nimport store from './store';\nimport router from './router';\n\nVue.use(VueI18n);\nVue.use(ElementUI);\n\nexport default {\n  router,\n  store,\n  components: {},\n  computed: {},\n  hook :{\n    render(context, vm) {\n      const i18n = createI18n(context.state.locale);\n      vm.i18n = i18n;\n    }\n  },\n  mounted() {},\n};\n```\n\n### easywebpack Entry Config\n\n```js\nmodule.exports = {\n  entry: {\n    app: 'app/web/page/admin/home/home.vue', // The entry will use the vue-entry-loader, not need to write the Vue initialization code\n    test: 'app/web/page/test/test.js' // The entry will not use the vue-entry-loader, you need to write the Vue initialization code\n  }\n};\n```\n\n## Feature\n\n### Dynamic Inject Template Code\n\n```js\nimport codeSegment from '${templateFile}'\ncodeSegment(Vue);\n```\n\n- Egg Project will inject the custom template code into the location above `${codeSegment}` when the file `app/web/framework/entry/template.js` exists\n- Non Egg Project will inject the custom template code into the location above `${codeSegment}` when the file `src/framework/entry/template.js` exists\n- The `entry/template.js` template file has the following constraints: \n\n    - import path must be absolute path, you can use webpack alias set\n    - export default must return function, the argument is Vue\n\n```js\n// import path must be absolute path, you can use webpack alias set\nimport Layout from 'component/layout/index'; \nimport plugin from 'framework/plugin';\n\n// must return function, the argument is Vue\nexport default function(Vue) {\n  Vue.use(plugin);\n  Vue.component(Layout.name, Layout);\n}\n```\n\n### Vue Entry File Initialization Hook Support\n\nsupport `hook.render` method for custom logic, such common component and logic initialization\n\n```js\nexport default {\n  hook :{\n    render(context, vm) {\n      const i18n = createI18n(context.state.locale);\n      vm.i18n = i18n;\n    }\n  },\n  computed: {},\n  mounted() {},\n};\n```\n\n### Vue Entry File Initialization Dynamic Store and Router\n\n**dynamic create store, solve the server side render singleton problem**\n\n```js\n// store/index.js\nexport default function createStore(initState) {\n  const state = {\n    ...initState\n  };\n  return new Vuex.Store({\n    state,\n    actions,\n    getters,\n    mutations\n  });\n}\n```\n\n- Dynamic Create Router\n\n```js\nexport default function createRouter() {\n  return new VueRouter({\n    mode: 'history',\n    base: '/',\n    routes: [\n      {\n        path: '/',\n        component: Dashboard\n      },\n      {\n        path: '*', component: () =\u003e import('../view/notfound.vue')\n      }\n    ]\n  });\n}\n```\n\n- Vue Entry File Code\n\n```js\nimport store from './store';\nimport router from './router';\n\nexport default {\n  router, // support Object and Function\n  store,  // support Object and Function\n  components: {},\n  computed: {},\n  mounted() {},\n};\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasy-team%2Fvue-entry-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasy-team%2Fvue-entry-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasy-team%2Fvue-entry-loader/lists"}