Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

vue-cli3 创建多页面应用,静态文件应该如何存放?

项目目录.png
如图,admin和user分别是两个多页面
vue.config.js的配置如下

const isDev = process.env.NODE_ENV !== 'production'

const path = require('path')
const resolve = dir => {
  return path.join(__dirname, dir)
}

const publicPath = '/'

const PAGES = {
  user: {
    entry: 'src/pages/user/main.js',
    template: 'src/pages/user/public/index.html',
    filename: 'index.html',
    title: 'IVTSP',
    chunks: ['chunk-vendors', 'chunk-common', 'user']
  },
  admin: {
    entry: 'src/pages/admin/main.js',
    template: 'src/pages/admin/public/operation.html',
    filename: 'operation.html',
    title: 'IVTSP-OPT',
    chunks: ['chunk-vendors', 'chunk-common', 'admin']
  }
}
let pages = {}
let dist = 'dist'
const pageName = process.argv[3]
if (isDev || !pageName) {
  pages = PAGES
} else {
  pages[pageName] = PAGES[pageName]
  dist = `${dist}_${pageName}`
}

module.exports = {
  publicPath,
  outputDir: dist,
  pages,
  /* webpack链式操作 */
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('_idx', resolve('src/pages/user'))
      .set('_opt', resolve('src/pages/admin'))
  },
  devServer: {
    historyApiFallback: {
      rewrites: [{
        from: new RegExp(`${publicPath}operation`),
        to: `${publicPath}operation.html`
      }]
    },
    open: true
  }
}

想引入一个不参与打包的config.js,现在是放在srcpagesuserpublicconfig.js路径,然后在srcpagesuserpublicindex.html中直接引入,但是发现定义的全局变量没有生效,引入的config.js也是报错404,求大佬指点!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

尝试了很久知道了。
在src同级下创建public文件夹,就跟vue-cli3本身的目录一样
vue.config.js中的不用改
因为route是采用history的模式
所以引入的方式是
<script src="/config.js"></script>
不能有前面的.,就可以了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...