配置文件package.json:

搜索了配置的原理:https://segmentfault.com/a/1190000000344102

里面讲到:npm会在package.json文件中找script区域,可以使用npm run 命令来运行scripts的任何条目

 "scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js",
"lint": "eslint --ext .js,.vue src"
}

可以知道npm run dev及npm run build是运行了相应的哪些文件:

(1)dev-server.js 和 build.js 分别引入了build文件下的 webpack.dev.conf 和 webpack.prod.conf 配置文件,而webpack.dev.conf.js 及 webpack.prod.conf.js文件都引入并整合了 webpack.base.conf.js 文件;

(2)dev-server.js和build.js也都引入了 config/index.js 文件,cinfig/index文件定义了build 和 dev 两个环境的各种参数,如下结构:
 module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
productionSourceMap: true,
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
},
dev: {
env: require('./dev.env'),
port: 8888,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
cssSourceMap: false
}
}

引入进去后,分别使用build模块和dev模块里的各种参数

能够在webpack.base.conf.js文件(如下)中看到主入口js文件是main.js

 let webpackConfig = {
entry: {
app: './src/main.js'
},....
}

另外在webpack.dev.conf.js 及 webpack.prod.conf.js 中能看到主入口页面的设置:HtmlWebpackPlugin

 //webpack.dev.conf.js
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}) //webpack.prod.conf.js
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
minify: {
...
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
})

main.js文件很重要,如下,它引入了需要引入的项目中的js、css文件(index.js、base.css),引入了依赖的模块(jsonp、vue、App、router),

新建了vue实例,将模块App挂载在id为app的元素上:

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import '@/common/js/index.js'
import '@/common/stylus/base.css'
import jsonp from 'jsonp'
import Vue from 'vue'
import App from './App'
import router from './router'
Vue.config.productionTip = false Vue.prototype.URL_PREFIX = 'http://139.196.7.54' Vue.prototype.jsonp = jsonp // 创建 启动应用
// 一定要确认注入了 router
// 在 <router-view> 中将会渲染路由组件
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})

router/index.js中

 import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login/login'
import index from '@/components/index/index'
import platelist from '@/components/platelist/platelist'
import choosecars from '@/components/choosecars/choosecars'
import vehiclemonitor from '@/components/vehiclemonitor/vehiclemonitor' // 插件
// 安装 <router-view> and <router-link> 组件
// 且给当前应用下所有的组件都注入 $router and $route 对象
Vue.use(Router) //实例化Router
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'login',
component: login
},
{
path: '/index',
name: 'index',
component: index
},
{
path: '/platelist',
name: 'platelist',
component: platelist
},
{
path: '/choosecars',
name: 'choosecars',
component: choosecars
},
{
path: '/vehiclemonitor',
name: 'vehiclemonitor',
component: vehiclemonitor
}
]
})

Vue-cli开发笔记一----------项目的结构的更多相关文章

  1. Vue Cli 3:创建项目

    一 简介 Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统,有几个独立的部分. 1 CLI (@vue/cli) 是一个全局安装的 npm 包,提供了终端里的 vue 命令.(vue ...

  2. vue cli 3.0创建项目

    .npm i -g @vue/cli .vue create my-project 此处有两个选择: 1.default (babel, eslint)默认套餐,提供babel和eslint支持 2. ...

  3. 让我们用Vue cli全家桶搭建项目

    一般项目都会用到这几个,这里不在详细介绍概念,只是简单的使用.一.搭建cli 1.事先安装好cnpm(淘宝镜像) npm install -g cnpm --registry=https://regi ...

  4. vue --- cli build 后的项目,图片路径出错

    今天在插入背景图片过程中,遇到了路径错误的问题,通过网上查询,找到了解决的办法,但是大部分都没有讲造成这种问题的原因,故我简单地总结了一下,并加入了一些自己的理解,欢迎共同探讨~ 当用vue-cli自 ...

  5. 项目中使用vue的API。 和项目的结构

    <template> <!--组件的 结构--> <div id="app"> <h3>{{ msg }}</h3> & ...

  6. Vue基础开发笔记

    以下实例代码地址:https://github.com/NewBLife/VueDev 1,Vue组件导入 新建组件:Header.vue <template> <div> & ...

  7. 使用Vue CLI 3快速创建项目

    首先 vue create ant-design-vue-pro 执行命令会显示两个选项,1默认,2自定义 我么选择自定义 选择好自定义的插件回车就等待下安装成功然后进入项目文件夹 cd ant-de ...

  8. vue cli 构建的 webpack 项目设置多页面

    1. webpack-dev-server下的设置(npm run dev) ./build/webpack.dev.conf.js 中,修改 new HtmlWebpackPlugin ,一个页面一 ...

  9. Vue CLI图形化创建项目

随机推荐

  1. vue - blog开发学习3

    1.添加less 和less-loader支持 npm install less less-loader --save-dev 2.新建main.less,将这个样式添加到home.vue中的cont ...

  2. wrong mechandise category

    Issue: cannot open masterdata for this two UPCs since the error below is displayed, but I checked an ...

  3. CSS2 从入门到精通

    1. 常用的选择器 1. 元素选择器 作用:通过元素选择器可以选择指定的元素 语法:tag{} p{ color: red; } h1{ color: red; } 2. id 选择器 作用:通过元素 ...

  4. 【最新】docker 安装elasticsearch + kibana步骤【第二篇_kibana】

    本文主要讲解Docker 安装 kibana并设置中文语言 [如果有需要安装elasticsearch 的朋友请移步博主第一篇文章] 话不多说! 第一步:docker 下载kibana docker ...

  5. 2018-8-29-Roslyn-静态分析

    title author date CreateTime categories Roslyn 静态分析 lindexi 2018-08-29 09:10:19 +0800 2018-03-13 14: ...

  6. 【leetcode】939. Minimum Area Rectangle

    题目如下: Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from t ...

  7. leetcood学习笔记-20

    python字符串与列表的相互转换   学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.s ...

  8. Debug - SpringBoot - Error starting ApplicationContext. To display the auto-configuration report re-runyour application

    Error log 2019-12-07 22:33:03.959 ERROR 3760 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ** ...

  9. 【TCP/IP】TCP的三次握手和四次挥手

    传输控制协议(TCP)是一种面向连接的协议,网络程序使用这个协议的时候,网络可以保证客户端和服务端的连接是可靠的,安全的. 如果 A机向 B机发送“hello”,在物理网线上传输的数据不仅仅是“hel ...

  10. PHP基础知识小结

    1.PHP中类型转换 自动转换 其它类型转换数值型 true->1 false->0 null->0 'true'->0 '-3abc'->-3 '3.123abc'-& ...