Skip to content

Commit

Permalink
feat: custom output file option (ktsn#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bencelang committed Oct 8, 2020
1 parent 06710c7 commit cf6cabd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions generator/index.js
Expand Up @@ -10,6 +10,7 @@ module.exports = (api) => {
pluginOptions: {
autoRouting: {
chunkNamePrefix: 'page-',
outFile: api.resolve('src/router/routes.js'),
},
},
},
Expand Down
@@ -1,6 +1,6 @@
import Vue from 'vue'
import Router from 'vue-router'
import routes from 'vue-auto-routing'
import routes from './routes'
import { createRouterLayout } from 'vue-router-layout'

Vue.use(Router)
Expand All @@ -10,6 +10,8 @@ const RouterLayout = createRouterLayout(layout => {
})

export default new Router({
mode: "history",
base: process.env.BASE_URL,
routes: [
{
path: '/',
Expand Down
11 changes: 11 additions & 0 deletions generator/template/src/router/routes.d.ts
@@ -0,0 +1,11 @@
/**
* This file is just for preventing compilation error of TypeScript code.
* Since `vue-auto-routing` is resolved with intercepted webpack plugin
* and is dynamically generated, the actual implementation does not exist
* in this package.
*/

import { RouteConfig } from 'vue-router'

declare const routes: RouteConfig[]
export default routes
1 change: 1 addition & 0 deletions generator/template/src/router/routes.js
@@ -0,0 +1 @@
export default [];
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -6,9 +6,11 @@ const defaultOptions = {
}

module.exports = (api, options) => {
const opts = options.pluginOptions && options.pluginOptions.autoRouting
const pluginOptions = {
...defaultOptions,
...(options.pluginOptions && options.pluginOptions.autoRouting),
...opts,
outFile: (opts && opts.outFile && api.resolve(opts.outFile)) || undefined,
}

api.chainWebpack((webpackConfig) => {
Expand Down

0 comments on commit cf6cabd

Please sign in to comment.