亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

vue-cli 3.0 多頁面 怎么配置?

vue-cli 3.0 多頁面 怎么配置?

躍然一笑 2018-08-23 22:06:40
版本: @vue/cli-service": "^3.0.0-beta.6配置了chaiWebpack,但configureWebpack不知道怎么配置,求指點~~vue.config.js 如下:module.exports = {   lintOnSave: false,   chainWebpack: config => {    config       .entry('one')       .add('./src/pages/one/one.ts')       .end()       .entry('two')       .add('./src/pages/two/two.ts')       .end()   },   configureWebpack: config => {    if (process.env.NODE_ENV === 'production') {      // mutate config for production...     } else {      // mutate for development...     }   } }
查看完整描述

2 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

可以直接在vue.config.js 中 設置 pages屬性來做到

// vue.config.jsmodule.exports = {
  pages: {    index: {      // 入口js的路徑
      entry: './src/views/index/entry',      // 頁面模板路徑
      template: `./src/views/index/index.html`
    }
  }
}

pages 可以遍歷獲得

在 @vue/cli-service/lib/config/app.js 中有下面一段,里面已經考慮了多頁的情況

// @vue/cli-service/lib/config/app.js...const multiPageConfig = options.pages

...if (!multiPageConfig) {  // default, single page setup.
  ......
} else {  // multi-page setup
  webpackConfig.entryPoints.clear()  const pages = Object.keys(multiPageConfig)
  pages.forEach(name => {    const {
      entry,
      template = `public/${name}.html`,
      filename = `${name}.html`
    } = multiPageConfig[name]    // inject entry
    webpackConfig.entry(name).add(api.resolve(entry))    // inject html plugin for the page
    const pageHtmlOptions = Object.assign({}, htmlOptions, {
      chunks: ['chunk-vendors', 'chunk-common', name],
      template: fs.existsSync(template) ? template : defaultHtmlPath,
      filename
    })

    webpackConfig
      .plugin(`html-${name}`)
        .use(HTMLPlugin, [pageHtmlOptions])
  })

  pages.forEach(name => {    const { filename = `${name}.html` } = multiPageConfig[name]
    webpackConfig
      .plugin(`preload-${name}`)
        .use(PreloadPlugin, [{
          rel: 'preload',
          includeHtmlNames: [filename],
          include: {            type: 'initial',
            entries: [name]
          },
          fileBlacklist: [/\.map$/, /hot-update\.js$/]
        }])

    webpackConfig
      .plugin(`prefetch-${name}`)
        .use(PreloadPlugin, [{
          rel: 'prefetch',
          includeHtmlNames: [filename],
          include: {            type: 'asyncChunks',
            entries: [name]
          }
        }])
  })
}


查看完整回答
反對 回復 2018-08-26
?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

// vue.config.js
module.exports = { 
pages: {

index: {  // entry for the page
  entry: 'src/main.js',  // the source template
  template: 'public/index.html',  // output as dist/index.html
  filename: 'index.html'},shareback: {  entry: 'src/shareback.js',  template: 'public/shareback.html',  filename: 'shareback.html'},

}
}


查看完整回答
反對 回復 2018-08-26
  • 2 回答
  • 0 關注
  • 3606 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號