vue + webpack工程化开发之多页站点

目录组织好,我们就可以开始撸代码了。

开发页面

在src/js/page目录下建立index.js文件,在src/view目录下建立index.html文件。入口js和模板文件名对应。

深刻理解下 webpack 的 HtmlWebpackPlugin 插件,因为文章的精髓就在这里。

一下贴一下我自己的多页面分离

      /*   入口文件*/
      module.exports = {
      entry: {
            index: './src/index.js',
            app: './src/main.js'
      },



    /* 配置文件  */
    plugins: [
    new webpack.DefinePlugin({
      'process.env': config.dev.env
    }),
    // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    // https://github.com/ampedandwired/html-webpack-plugin
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true,
            chunks:['index']      //指入口文件
    }),
        new HtmlWebpackPlugin({
            filename: 'info.html',
            template: 'info.html',
            inject: true,
            chunks: ['app']      //指入口文件
        })
  ]