Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多页面应用,如何将每个页面自身的内容单独打包,例:dist/page1, dist/page2 ? #2861

Closed
galaa2011 opened this issue Oct 31, 2018 · 14 comments

Comments

@galaa2011
Copy link

What problem does this feature solve?

多页面build时的输出问题

What does the proposed API look like?

能打包成多个独立模块

@galaa2011
Copy link
Author

本来想通过执行vue-cli-service build xxx,获取参数来动态传入pages的内容,发现vue.config.js里也接不到...
求指条明路~

@galaa2011
Copy link
Author

3.x的版本限制的太死了,很多不如之前自己写那么灵活

@haoqunjiang
Copy link
Member

https://cli.vuejs.org/zh/config/#pages

@galaa2011
Copy link
Author

@sodatea 兄dei 你发这个链接就不走心吧

@haoqunjiang
Copy link
Member

请说清楚你的需求。

@galaa2011
Copy link
Author

多页面配置没毛病,但是我想build出来的内容也能是独立的。即page1下包含完整的css,js,img等这些资源,page2也是。我看现在的情况,默认是混在一起,且vendors里包含了page1、page2共有的库。

@galaa2011
Copy link
Author

@sodatea 有好的解决办法,或者思路吗?

@jkzing
Copy link
Member

jkzing commented Nov 6, 2018

// vue.config.js
const configs = {
  page1: {
    outputDir: 'page1'
    configureWebpack() {
      return {
        entry: 'src/page1.js'
      }
    }
  },
  page2: {
    outputDir: 'page2',
    configureWebpack() {
      return {
        entry: 'src/page2.js'
      }
    }
  }
}

module.exports = configs[process.env.PAGE_CONF]
PAGE_CONF=page1 && npm run build
# or
PAGE_CONF=page2 && npm run build

@qhhsy
Copy link

qhhsy commented Nov 7, 2018

@jkzing 您好,请教下如何打包目录下所有多页呢?

@galaa2011
Copy link
Author

@jkzing @sodatea 多谢两位,是这个思路。后来我通过参数判断了,类似build后面的h5hb

"scripts": {
  "serve": "vue-cli-service serve",
  "build": "vue-cli-service build",
  "build:h5": "vue-cli-service build h5",
  "build:hb": "vue-cli-service build hb",
  "build:all": "npm run build & npm run build:h5 & npm run build:hb",
  "lint": "vue-cli-service lint",
  "test:unit": "vue-cli-service test:unit"
}

在vue.config.js里通过

let build = process.argv.slice(2)[1];

获取build参数值来传入不同的pagesoutputDir

@galaa2011
Copy link
Author

@qhhsy 看上面这行~

"build:all": "npm run build & npm run build:h5 & npm run build:hb",

@qhhsy
Copy link

qhhsy commented Nov 8, 2018

谢谢

@qhhsy
Copy link

qhhsy commented Nov 9, 2018

这种情况需要指定打包的页面,能做成自动打包吗?

@lh4111
Copy link

lh4111 commented Dec 8, 2018

这种情况需要指定打包的页面,能做成自动打包吗?

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants