4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
新闻详情
vue全家桶安装以及修改webpack配置新增vue项目启动方式- 每日博客
来自 : blog.huati365.com/6651a5422cdd 发布时间:2021-03-24

一、安装node环境(自带npm)

下载地址

\"分享图片\"

二、替换下载源

// 淘宝 NPM 镜像npm install -g cnpm --registry=https://registry.npm.taobao.org

\"分享图片\"

三、全局安装vue-cli脚手架

npm install --global vue-cli

四、vue2.* webpack模板下载

vue init webpack vue_project

\"分享图片\"

五、安装vuex

npm install vuex --save

\"分享图片\"

在main.js中注入vuex

// vueximport Vuex from ‘vuex‘Vue.use(Vuex)

六、安装axios

npm install axios --save

\"分享图片\"

在main.js导入并全局使用

// axios请求import axios from \"axios\"Vue.prototype.$axios = axios

七、安装elementUI

npm install element-ui --save

\"分享图片\"

在main.js中引入elementUI

// element样式框架import ElementUI from ‘element-ui‘
import ‘element-ui/lib/theme-chalk/index.css‘
Vue.use(ElementUI)

八、vue项目使用sass

npm install sass-loader --save-devnpm install node-sass --save-dev

//连写
npm install sass-loader node-sass --save-dev

\"分享图片\"

想要使用sass,需要修改build目录下的webpack.base.conf.js文件,增加以下规则:

{ test: /.sass$/, loaders: [‘style‘, ‘css‘, ‘sass‘,\"scss\"]}

在组件中使用sass语法

 style lang=\"scss\"  $size:50px; html { font-size: $size; /style 

或者外部引用:

 style lang=\"scss\"  @import \"./main.scss\" // 或者 // @import url(./main.scss); /style 

九、修改webpack配置,新增项目启动方式

以 pred 为例:

1,首先更改package.json配置

\"分享图片\"

2,在build目录下增加pred.js,内容和build.js文件相同,更改以下两处变量即可

\"分享图片\"

3.修改build目录下webpack.prod.conf.js配置,替换如下代码:

‘use strict‘const path = require(‘path‘)const utils = require(‘./utils‘)const webpack = require(‘webpack‘)const config = require(‘../config‘)const merge = require(‘webpack-merge‘)const baseWebpackConfig = require(‘./webpack.base.conf‘)const CopyWebpackPlugin = require(‘copy-webpack-plugin‘)const HtmlWebpackPlugin = require(‘html-webpack-plugin‘)const ExtractTextPlugin = require(‘extract-text-webpack-plugin‘)const OptimizeCSSPlugin = require(‘optimize-css-assets-webpack-plugin‘)const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin‘)/** 删除内容 const env = process.env.NODE_ENV === ‘testing‘ ? require(‘../config/test.env‘) : require(‘../config/prod.env‘)// 替换成 const ENV_MAP = { ‘testing‘: require(‘../config/test.env‘), ‘production‘: require(‘../config/prod.env‘), ‘pred‘: require(‘../config/pred.env‘) const env = process.env.NODE_ENV = ENV_MAP[process.env.NODE_ENV];

4.在config目录新增 pred.env.js文件,内容如下

‘use strict‘module.exports = { NODE_ENV: ‘\"pred\"‘}

5.修改config目录下的index.js,复制build对象并修改成pred

build: { // Template for index.html index: path.resolve(__dirname, ‘../dist/index.html‘), // Paths assetsRoot: path.resolve(__dirname, ‘../dist‘), assetsSubDirectory: ‘static‘, assetsPublicPath: ‘/‘, * Source Maps productionSourceMap: true, // https://webpack.js.org/configuration/devtool/#production devtool: ‘#source-map‘, // 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 pred: { // Template for index.html index: path.resolve(__dirname, ‘../dist/index.html‘), // Paths assetsRoot: path.resolve(__dirname, ‘../dist‘), assetsSubDirectory: ‘static‘, assetsPublicPath: ‘/‘, * Source Maps productionSourceMap: true, // https://webpack.js.org/configuration/devtool/#production devtool: ‘#source-map‘, // 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 }

6,控制台输入 npm run pred,看到如下内容即成功:

\"分享图片\"

本文链接: http://axiostrading.immuno-online.com/view-716974.html

发布于 : 2021-03-24 阅读(0)