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

可以增加一个用于多页面开发的模板吗? #155

Closed
playniuniu opened this issue Aug 26, 2016 · 2 comments
Closed

可以增加一个用于多页面开发的模板吗? #155

playniuniu opened this issue Aug 26, 2016 · 2 comments

Comments

@playniuniu
Copy link

对 webpack 不是很熟悉,但是希望能够进行多页面开发,能生成一个基于 webpack-simple 但是可以用于多页面开发的模板吗?

@posva
Copy link
Member

posva commented Aug 26, 2016

Hi!

Please make sure to ask the question on the forums or the gitter chat.

As for your question, not sure about what you mean by multi-page app. The build process may vary depending on the backend. Make sure to add that information when asking for help on the forums or on the gitter chat.

@posva posva closed this as completed Aug 26, 2016
@wengcd
Copy link

wengcd commented Mar 15, 2017

@playniuniu 试试这个 有些地方省略了。主要告诉它依赖关系就行了

example

client.html
admin.html

// build/webpack.base.conf.js
module.exports = {
  entry: {
    client: './src/client.js',
    admin: './src/admin.js'
  },
  ...
}
// build/webpack.dev.conf.js
{
  ...
  new HtmlWebpackPlugin({
    filename: 'client.html',
    template: 'client.html',
    chunks: ['client'],
    inject: true
  }),
  new HtmlWebpackPlugin({
    filename: 'admin.html',
    template: 'admin.html',
    chunks: ['admin'],
    inject: true
  }),
  ...
}
// build/webpack.prod.conf.js
{
  ...
  new HtmlWebpackPlugin({
      filename: config.build.client,
      template: 'client.html',
      chunks: ['client', 'client-vendor', 'client-manifest'],
      ....
    }),
    new HtmlWebpackPlugin({
      filename: config.build.admin,
      template: 'admin.html',
      chunks: ['admin', 'admin-vendor', 'admin-manifest']
      ...
    }),
    // split vendor js into its own file
    new webpack.optimize.CommonsChunkPlugin({
      name: 'client-vendor',
      chunks: ['client'],
      ...
    }),
    // split vendor js into its own file
    new webpack.optimize.CommonsChunkPlugin({
      name: 'admin-vendor',
      chunks: ['admin'],
      ...
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'client-manifest',
      chunks: ['client-vendor']
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'admin-manifest',
      chunks: ['admin-vendor']
    }),
  ...
}
// config/index.js
module.exports = {
  build: {
    env: require('./prod.env'),
    client: path.resolve(__dirname, '../dist/client.html'),
    admin: path.resolve(__dirname, '../dist/admin.html'),
    ...
  }
}

不过有个坏处,就是只修改了一个页面,build的时候会编译全部。所以所在的页面项目比较大的话可以在原有的配置上,拷贝出副本,然后修改下配置。再用命令比如npm run build:client的方式来处理

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

3 participants