文件目录

  1. ├─build
  2. ├─config
  3. ├─dist
  4. └─static
  5. ├─css
  6. ├─img
  7. └─js
  8. ├─src
  9. ├─assets
  10. ├─img
  11. ├─js
  12. ├─lib
  13. └─style
  14. ├─components
  15. └─pages
  16. ├─activitydetails
  17. └─router
  18. ├─getgift
  19. └─router
  20. └─gettask
  21. └─router
  22. └─static

buil/utils.js中新增如下代码

  1. //多入口配置
  2. // 通过glob模块读取pages文件夹下的所有对应文件夹下的js后缀文件,如果该文件存在
  3. // 那么就作为入口处理
  4. exports.entries = function() {
  5. var entryFiles = glob.sync(PAGE_PATH + '/*/*.js')
  6. var map = {}
  7. entryFiles.forEach((filePath) => {
  8. var filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
  9. map[filename] = filePath
  10. })
  11. return map
  12. }
  13.  
  14. /**
  15. * 以下是多页配置的函数
  16. */
  17.  
  18. // glob是webpack安装时依赖的一个第三方模块,还模块允许你使用 *等符号, 例如lib/*.js就是获取lib文件夹下的所有js后缀名的文件
  19. var glob = require('glob')
  20. // 页面模板
  21. var HtmlWebpackPlugin = require('html-webpack-plugin')
  22. // 取得相应的页面路径,因为之前的配置,所以是src文件夹下的pages文件夹
  23. var PAGE_PATH = path.resolve(__dirname, '../src/pages')
  24. // 用于做相应的merge处理
  25. var merge = require('webpack-merge')
  26.  
  27. //多页面输出配置
  28. // 与上面的多页面入口配置相同,读取pages文件夹下的对应的html后缀文件,然后放入数组中
  29. exports.htmlPlugin = function() {
  30. let entryHtml = glob.sync(PAGE_PATH + '/*/*.html')
  31. let arr = []
  32. entryHtml.forEach((filePath) => {
  33. let filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
  34. let conf = {
  35. // 模板来源
  36. template: filePath,
  37. // 文件名称
  38. filename: filename + '.html',
  39. // 页面模板需要加对应的js脚本,如果不加这行则每个页面都会引入所有的js脚本
  40. chunks: ['manifest', 'vendor', filename],
  41. inject: true
  42. }
  43. if (process.env.NODE_ENV === 'production') {
  44. conf = merge(conf, {
  45. minify: {
  46. removeComments: true,
  47. collapseWhitespace: true,
  48. removeAttributeQuotes: true
  49. },
  50. chunksSortMode: 'dependency'
  51. })
  52. }
  53. arr.push(new HtmlWebpackPlugin(conf))
  54. })
  55. return arr
  56. }

build/webpack.base.conf.js

  1. entry: utils.entries()

  

build/webpack.dev.conf.js  

// 将原来的HtmlWebpackPlugin 注释掉(红色部分)

// 再加上绿色标记的部分
  1. module.exports = merge(baseWebpackConfig, {
  2. module: {
  3. rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
  4. },
  5. // cheap-module-eval-source-map is faster for development
  6. devtool: '#cheap-module-eval-source-map',
  7. plugins: [
  8. new webpack.DefinePlugin({
  9. 'process.env': config.dev.env
  10. }),
  11. // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
  12. new webpack.HotModuleReplacementPlugin(),
  13. new webpack.NoEmitOnErrorsPlugin(),
  14. // https://github.com/ampedandwired/html-webpack-plugin
  15. // new HtmlWebpackPlugin({
  16. // filename: 'index.html',
  17. // template: 'index.html',
  18. // inject: true
  19. // }),
  20. new FriendlyErrorsPlugin()
  21. ].concat(utils.htmlPlugin())
  22. })

  

build/webpack.prod.conf.js

  1. var webpackConfig = merge(baseWebpackConfig, {
  2. module: {
  3. rules: utils.styleLoaders({
  4. sourceMap: config.build.productionSourceMap,
  5. extract: true
  6. })
  7. },
  8. devtool: config.build.productionSourceMap ? '#source-map' : false,
  9. output: {
  10. path: config.build.assetsRoot,
  11. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  12. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  13. },
  14. plugins: [
  15. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  16. new webpack.DefinePlugin({
  17. 'process.env': env
  18. }),
  19. new webpack.optimize.UglifyJsPlugin({
  20. compress: {
  21. warnings: false
  22. },
  23. sourceMap: true
  24. }),
  25. // extract css into its own file
  26. new ExtractTextPlugin({
  27. filename: utils.assetsPath('css/[name].[contenthash].css')
  28. }),
  29. // Compress extracted CSS. We are using this plugin so that possible
  30. // duplicated CSS from different components can be deduped.
  31. new OptimizeCSSPlugin({
  32. cssProcessorOptions: {
  33. safe: true
  34. }
  35. }),
  36. // generate dist index.html with correct asset hash for caching.
  37. // you can customize output by editing /index.html
  38. // see https://github.com/ampedandwired/html-webpack-plugin
  39. // new HtmlWebpackPlugin({
  40. // filename: config.build.index,
  41. // template: 'index.html',
  42. // inject: true,
  43. // minify: {
  44. // removeComments: true,
  45. // collapseWhitespace: true,
  46. // removeAttributeQuotes: true
  47. // // more options:
  48. // // https://github.com/kangax/html-minifier#options-quick-reference
  49. // },
  50. // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  51. // chunksSortMode: 'dependency'
  52. // }),
  53. // split vendor js into its own file
  54. new webpack.optimize.CommonsChunkPlugin({
  55. name: 'vendor',
  56. minChunks: function (module, count) {
  57. // any required modules inside node_modules are extracted to vendor
  58. return (
  59. module.resource &&
  60. /\.js$/.test(module.resource) &&
  61. module.resource.indexOf(
  62. path.join(__dirname, '../node_modules')
  63. ) === 0
  64. )
  65. }
  66. }),
  67. // extract webpack runtime and module manifest to its own file in order to
  68. // prevent vendor hash from being updated whenever app bundle is updated
  69. new webpack.optimize.CommonsChunkPlugin({
  70. name: 'manifest',
  71. chunks: ['vendor']
  72. }),
  73. // copy custom static assets
  74. new CopyWebpackPlugin([
  75. {
  76. from: path.resolve(__dirname, '../static'),
  77. to: config.build.assetsSubDirectory,
  78. ignore: ['.*']
  79. }
  80. ])
  81. ].concat(utils.htmlPlugin())
  82. })

  

  

vue项目多页配置的更多相关文章

  1. rem的在vue项目中使用配置,,浏览器的兼容性之Mate标签

    在vue中配置rem 位置:在APP.vue的script中,在export default之外 (()=>{ let winW = document.documentElement.clien ...

  2. vue项目实战, webpack 配置流程记录

    vue项目实战记录,地址在这 购物车单界面 npm install npm run dev 跑起来可以看到界面效果 这里简单记录一下webpack的编译流程 入口 package.json " ...

  3. VSCode中使用vue项目ESlint验证配置

    如果在一个大型项目中会有多个人一起去开发,为了使每个人写的代码格式都保持一致,就需要借助软件去帮我们保存文件的时候,自己格式化代码 解决办法:vscode软件下载一个ESLint,在到设置里面找到se ...

  4. Vue 项目中 ESlint 配置

    前言 对于 ESlint 这一块一直存在一些疑问,今天看到一个文章内容挺好的,这里拿来了. 一.eslint 安装 1.全局安装 npm i -g eslint 全局安装的好处是,在任何项目我们都可以 ...

  5. vue项目eslint环境配置与vscode配置eslint

    eslint基础环境搭建 全局安装eslint:npm install eslint -g 项目eslint初始化:eslint --init,按团队或自己的编程风格回答三道题. ? How woul ...

  6. vue项目的路由配置

    方案一.在生成项目的时候就选择安装路由; 这个地方选择y即可; 生成项目之后在src目录下会有router文件夹,里面有index.js,并且里面已经存在一个helloWorld页面了,可以直接模仿着 ...

  7. vue项目打包文件配置(vue-clli3)

    练手项目完结打包的时候遇到一些问题,特此记录 先贴我的vue.config.js文件的代码(vue-cli3构建的项目默认是没有此文件的,需手动添加)更多详细配置参考官方配置文档,我的项目不大不小,这 ...

  8. vue项目的实用配置

    文件压缩如何去掉console 在使用vue开发项目的过程中,免不了在调试的时候会写许多console,在控制台进行调试:在开发的时候这种输出是必须的,但是build后线上运行时这个东西是不能出现的: ...

  9. vue项目的常用配置代码

    { // 针对vue的格式化配置----依赖eslint.prettier.vetur等插件 // 强制单引号 "prettier.singleQuote": true, &quo ...

随机推荐

  1. UVA 1203 - Argus(优先队列)

    UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...

  2. POJ 1742 Coins(多重背包, 单调队列)

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  3. VS2015编译OpenSSL1.0.2源码

    更多详细信息http://blog.csdn.net/YAOJINGKAO/article/details/53041165?locationNum=10&fps=1 1.下载安装编译必须的A ...

  4. 如何使用微信小程序制作banner轮播图?

    在前端工程师的工作中,banner是必不可少的,那缺少了DOM的小程序是如何实现banner图的呢?如同其他的框架封装了不同的banner图的方法,小程序也封装了banner的方法,来让我一一道来: ...

  5. WIN10 X64下通过TLS实现反调试

    目录(?)[-] TLS技术简介 1 TLS回调函数 2 TLS的数据结构 具体实现及原理 1 VS2015 X64 release下的demo 2 回调函数的具体实现 21 使用IsDebugger ...

  6. CSS3 Transform变形(2D转换)

    Transform:对元素进行变形:Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开始,结束.Animation:对元素某个属性 ...

  7. 日记整理---->2016-11-23

    这里放一些jquery的学习知识.可能从一开始就是我一个人单枪匹马,来年不求并肩作战,只愿所向披靡. jquery的学习一 jquery关于ajax的一些学习博客 ajax方法的介绍:https:// ...

  8. sencha touch 扩展篇之使用sass自定义主题样式 (上)使用官方的api修改主题样式

    大家知道,sencha touch是通过我们写的js代码来动态渲染单页面生成一个个div+css的html页面来模拟app应用,那么既然是div+css结构的,我们就可以通过修改css样式来自定义我们 ...

  9. 使用as3crypto在Flex中实现AES加密

    要在Flex中实现AES加密,可以通过as3crypto实现.但是as3crypto本身的用法比较复杂,一般是封装一下再调用. 下面是9RIA上的一篇文章给出的一个实现,使用中稍感不方便(见注释): ...

  10. 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树

    [BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...