Vue-VueRouter-Webpack 项目教程

Vue-VueRouter-Webpack 项目教程

vue-vueRouter-webpackA base vue project with webpack项目地址:https://gitcode.com/gh_mirrors/vu/vue-vueRouter-webpack

1. 项目的目录结构及介绍

vue-vueRouter-webpack/
├── build/                  # Webpack 配置文件目录
│   ├── webpack.base.conf.js # 基础配置文件
│   ├── webpack.dev.conf.js  # 开发环境配置文件
│   └── webpack.prod.conf.js # 生产环境配置文件
├── config/                 # 项目配置目录
│   ├── dev.env.js          # 开发环境变量
│   ├── index.js            # 主要配置文件
│   └── prod.env.js         # 生产环境变量
├── src/                    # 源代码目录
│   ├── assets/             # 静态资源目录
│   ├── components/         # Vue 组件目录
│   ├── router/             # Vue Router 配置目录
│   ├── App.vue             # 根组件
│   └── main.js             # 入口文件
├── static/                 # 静态文件目录
├── .babelrc                # Babel 配置文件
├── .editorconfig           # 编辑器配置文件
├── .gitignore              # Git 忽略文件配置
├── index.html              # 入口 HTML 文件
├── package.json            # 项目依赖和脚本配置
└── README.md               # 项目说明文档

2. 项目的启动文件介绍

main.js

main.js 是项目的入口文件,主要负责初始化 Vue 实例并引入必要的模块和配置。以下是 main.js 的基本结构:

import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
  • import Vue from 'vue':引入 Vue 库。
  • import App from './App':引入根组件 App.vue
  • import router from './router':引入 Vue Router 配置。
  • Vue.config.productionTip = false:关闭生产环境提示。
  • new Vue({...}):创建 Vue 实例,挂载到 #app 元素上。

3. 项目的配置文件介绍

config/index.js

config/index.js 是项目的主要配置文件,定义了开发和生产环境的配置参数。以下是 config/index.js 的基本结构:

module.exports = {
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    productionSourceMap: true,
    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  },
  dev: {
    env: require('./dev.env'),
    port: 8080,
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  }
}
  • build 对象:定义了生产环境的配置,如输出目录、资源路径、Gzip 压缩等。
  • dev 对象:定义了开发环境的配置,如端口号、自动打开浏览器、代理设置

vue-vueRouter-webpackA base vue project with webpack项目地址:https://gitcode.com/gh_mirrors/vu/vue-vueRouter-webpack

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翁然眉Esmond

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值