vue项目多页配置
文件目录
- ├─build
- ├─config
- ├─dist
- │ └─static
- │ ├─css
- │ ├─img
- │ └─js
- ├─src
- │ ├─assets
- │ │ ├─img
- │ │ ├─js
- │ │ ├─lib
- │ │ └─style
- │ ├─components
- │ └─pages
- │ ├─activitydetails
- │ │ └─router
- │ ├─getgift
- │ │ └─router
- │ └─gettask
- │ └─router
- └─static
buil/utils.js中新增如下代码
- //多入口配置
- // 通过glob模块读取pages文件夹下的所有对应文件夹下的js后缀文件,如果该文件存在
- // 那么就作为入口处理
- exports.entries = function() {
- var entryFiles = glob.sync(PAGE_PATH + '/*/*.js')
- var map = {}
- entryFiles.forEach((filePath) => {
- var filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
- map[filename] = filePath
- })
- return map
- }
- /**
- * 以下是多页配置的函数
- */
- // glob是webpack安装时依赖的一个第三方模块,还模块允许你使用 *等符号, 例如lib/*.js就是获取lib文件夹下的所有js后缀名的文件
- var glob = require('glob')
- // 页面模板
- var HtmlWebpackPlugin = require('html-webpack-plugin')
- // 取得相应的页面路径,因为之前的配置,所以是src文件夹下的pages文件夹
- var PAGE_PATH = path.resolve(__dirname, '../src/pages')
- // 用于做相应的merge处理
- var merge = require('webpack-merge')
- //多页面输出配置
- // 与上面的多页面入口配置相同,读取pages文件夹下的对应的html后缀文件,然后放入数组中
- exports.htmlPlugin = function() {
- let entryHtml = glob.sync(PAGE_PATH + '/*/*.html')
- let arr = []
- entryHtml.forEach((filePath) => {
- let filename = filePath.substring(filePath.lastIndexOf('\/') + 1, filePath.lastIndexOf('.'))
- let conf = {
- // 模板来源
- template: filePath,
- // 文件名称
- filename: filename + '.html',
- // 页面模板需要加对应的js脚本,如果不加这行则每个页面都会引入所有的js脚本
- chunks: ['manifest', 'vendor', filename],
- inject: true
- }
- if (process.env.NODE_ENV === 'production') {
- conf = merge(conf, {
- minify: {
- removeComments: true,
- collapseWhitespace: true,
- removeAttributeQuotes: true
- },
- chunksSortMode: 'dependency'
- })
- }
- arr.push(new HtmlWebpackPlugin(conf))
- })
- return arr
- }
build/webpack.base.conf.js
- entry: utils.entries()
build/webpack.dev.conf.js
// 将原来的HtmlWebpackPlugin 注释掉(红色部分)
- module.exports = merge(baseWebpackConfig, {
- module: {
- rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
- },
- // cheap-module-eval-source-map is faster for development
- devtool: '#cheap-module-eval-source-map',
- plugins: [
- new webpack.DefinePlugin({
- 'process.env': config.dev.env
- }),
- // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
- new webpack.HotModuleReplacementPlugin(),
- new webpack.NoEmitOnErrorsPlugin(),
- // https://github.com/ampedandwired/html-webpack-plugin
- // new HtmlWebpackPlugin({
- // filename: 'index.html',
- // template: 'index.html',
- // inject: true
- // }),
- new FriendlyErrorsPlugin()
- ].concat(utils.htmlPlugin())
- })
build/webpack.prod.conf.js
- var webpackConfig = merge(baseWebpackConfig, {
- module: {
- rules: utils.styleLoaders({
- sourceMap: config.build.productionSourceMap,
- extract: true
- })
- },
- devtool: config.build.productionSourceMap ? '#source-map' : false,
- output: {
- path: config.build.assetsRoot,
- filename: utils.assetsPath('js/[name].[chunkhash].js'),
- chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
- },
- plugins: [
- // http://vuejs.github.io/vue-loader/en/workflow/production.html
- new webpack.DefinePlugin({
- 'process.env': env
- }),
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- warnings: false
- },
- sourceMap: true
- }),
- // extract css into its own file
- new ExtractTextPlugin({
- filename: utils.assetsPath('css/[name].[contenthash].css')
- }),
- // Compress extracted CSS. We are using this plugin so that possible
- // duplicated CSS from different components can be deduped.
- new OptimizeCSSPlugin({
- cssProcessorOptions: {
- safe: true
- }
- }),
- // generate dist index.html with correct asset hash for caching.
- // you can customize output by editing /index.html
- // see https://github.com/ampedandwired/html-webpack-plugin
- // new HtmlWebpackPlugin({
- // filename: config.build.index,
- // template: 'index.html',
- // inject: true,
- // minify: {
- // removeComments: true,
- // collapseWhitespace: true,
- // removeAttributeQuotes: true
- // // more options:
- // // https://github.com/kangax/html-minifier#options-quick-reference
- // },
- // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
- // chunksSortMode: 'dependency'
- // }),
- // split vendor js into its own file
- new webpack.optimize.CommonsChunkPlugin({
- name: 'vendor',
- minChunks: function (module, count) {
- // any required modules inside node_modules are extracted to vendor
- return (
- module.resource &&
- /\.js$/.test(module.resource) &&
- module.resource.indexOf(
- path.join(__dirname, '../node_modules')
- ) === 0
- )
- }
- }),
- // extract webpack runtime and module manifest to its own file in order to
- // prevent vendor hash from being updated whenever app bundle is updated
- new webpack.optimize.CommonsChunkPlugin({
- name: 'manifest',
- chunks: ['vendor']
- }),
- // copy custom static assets
- new CopyWebpackPlugin([
- {
- from: path.resolve(__dirname, '../static'),
- to: config.build.assetsSubDirectory,
- ignore: ['.*']
- }
- ])
- ].concat(utils.htmlPlugin())
- })
vue项目多页配置的更多相关文章
- rem的在vue项目中使用配置,,浏览器的兼容性之Mate标签
在vue中配置rem 位置:在APP.vue的script中,在export default之外 (()=>{ let winW = document.documentElement.clien ...
- vue项目实战, webpack 配置流程记录
vue项目实战记录,地址在这 购物车单界面 npm install npm run dev 跑起来可以看到界面效果 这里简单记录一下webpack的编译流程 入口 package.json " ...
- VSCode中使用vue项目ESlint验证配置
如果在一个大型项目中会有多个人一起去开发,为了使每个人写的代码格式都保持一致,就需要借助软件去帮我们保存文件的时候,自己格式化代码 解决办法:vscode软件下载一个ESLint,在到设置里面找到se ...
- Vue 项目中 ESlint 配置
前言 对于 ESlint 这一块一直存在一些疑问,今天看到一个文章内容挺好的,这里拿来了. 一.eslint 安装 1.全局安装 npm i -g eslint 全局安装的好处是,在任何项目我们都可以 ...
- vue项目eslint环境配置与vscode配置eslint
eslint基础环境搭建 全局安装eslint:npm install eslint -g 项目eslint初始化:eslint --init,按团队或自己的编程风格回答三道题. ? How woul ...
- vue项目的路由配置
方案一.在生成项目的时候就选择安装路由; 这个地方选择y即可; 生成项目之后在src目录下会有router文件夹,里面有index.js,并且里面已经存在一个helloWorld页面了,可以直接模仿着 ...
- vue项目打包文件配置(vue-clli3)
练手项目完结打包的时候遇到一些问题,特此记录 先贴我的vue.config.js文件的代码(vue-cli3构建的项目默认是没有此文件的,需手动添加)更多详细配置参考官方配置文档,我的项目不大不小,这 ...
- vue项目的实用配置
文件压缩如何去掉console 在使用vue开发项目的过程中,免不了在调试的时候会写许多console,在控制台进行调试:在开发的时候这种输出是必须的,但是build后线上运行时这个东西是不能出现的: ...
- vue项目的常用配置代码
{ // 针对vue的格式化配置----依赖eslint.prettier.vetur等插件 // 强制单引号 "prettier.singleQuote": true, &quo ...
随机推荐
- UVA 1203 - Argus(优先队列)
UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...
- POJ 1742 Coins(多重背包, 单调队列)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- VS2015编译OpenSSL1.0.2源码
更多详细信息http://blog.csdn.net/YAOJINGKAO/article/details/53041165?locationNum=10&fps=1 1.下载安装编译必须的A ...
- 如何使用微信小程序制作banner轮播图?
在前端工程师的工作中,banner是必不可少的,那缺少了DOM的小程序是如何实现banner图的呢?如同其他的框架封装了不同的banner图的方法,小程序也封装了banner的方法,来让我一一道来: ...
- WIN10 X64下通过TLS实现反调试
目录(?)[-] TLS技术简介 1 TLS回调函数 2 TLS的数据结构 具体实现及原理 1 VS2015 X64 release下的demo 2 回调函数的具体实现 21 使用IsDebugger ...
- CSS3 Transform变形(2D转换)
Transform:对元素进行变形:Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开始,结束.Animation:对元素某个属性 ...
- 日记整理---->2016-11-23
这里放一些jquery的学习知识.可能从一开始就是我一个人单枪匹马,来年不求并肩作战,只愿所向披靡. jquery的学习一 jquery关于ajax的一些学习博客 ajax方法的介绍:https:// ...
- sencha touch 扩展篇之使用sass自定义主题样式 (上)使用官方的api修改主题样式
大家知道,sencha touch是通过我们写的js代码来动态渲染单页面生成一个个div+css的html页面来模拟app应用,那么既然是div+css结构的,我们就可以通过修改css样式来自定义我们 ...
- 使用as3crypto在Flex中实现AES加密
要在Flex中实现AES加密,可以通过as3crypto实现.但是as3crypto本身的用法比较复杂,一般是封装一下再调用. 下面是9RIA上的一篇文章给出的一个实现,使用中稍感不方便(见注释): ...
- 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树
[BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...