使用vue-cli創(chuàng)建項(xiàng)目并webpack打包的操作方法
1.準(zhǔn)備環(huán)境(nodejs下載和設(shè)置環(huán)境變量)2.全局安裝vue-cli,提供vue命令進(jìn)行創(chuàng)建vue項(xiàng)目
npm install -g @vue/cli
關(guān)于舊版本Vue CLI 的包名稱由 vue-cli 改成了 @vue/cli。 如果你已經(jīng)全局安裝了舊版本的 vue-cli (1.x 或 2.x),你需要先通過(guò) npm uninstall vue-cli -g 或 yarn global remove vue-cli 卸載它。
3.創(chuàng)建一個(gè)基于 webpack 模板的新項(xiàng)目(先新建項(xiàng)目文件夾,打開(kāi)所在位置命令行)
vue init webpack my-project
4.進(jìn)行默認(rèn)配置
# 這里需要進(jìn)行一些配置,默認(rèn)回車即可This will install Vue 2.x version of the template.For Vue 1.x use: vue init webpack#1.0 my-project# 開(kāi)始配置? Project name my-project? Project description A Vue.js project? Author runoob <test@runoob.com>? Vue build standalone? Use ESLint to lint your code? Yes? Pick an ESLint preset Standard? Setup unit tests with Karma + Mocha? Yes? Setup e2e tests with Nightwatch? Yes# 配置結(jié)束 vue-cli · Generated 'my-project'. To get started:cd my-project npm install npm run dev Documentation can be found at https://vuejs-templates.github.io/webpack
5.進(jìn)入項(xiàng)目,安裝node_modules,并啟動(dòng)項(xiàng)目
cd my-projectnpm installnpm run dev
6.打包項(xiàng)目,并且配置nginx
# 打包項(xiàng)目npm run build
nginx配置
worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfileon; keepalive_timeout 65; server {listen 8081;server_name localhost;location / { root E:/vuework/my-project/dist;try_files $uri $uri/ /index.html; index index.html index.htm;} }}
7.重復(fù)打包,文件不更新問(wèn)題。在build目錄下的webpack打包文件引用clean-webpack-plugin插件,然后在plugin中使用即可。
8.部署:配置nginx,打包項(xiàng)目,啟動(dòng)nginx即可
npm run buildstart nginx
到此這篇關(guān)于使用vue-cli創(chuàng)建項(xiàng)目,webpack打包的文章就介紹到這了,更多相關(guān)vue webpack打包內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法2. python讓函數(shù)不返回結(jié)果的方法3. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器4. PHP循環(huán)與分支知識(shí)點(diǎn)梳理5. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案6. Python TestSuite生成測(cè)試報(bào)告過(guò)程解析7. chat.asp聊天程序的編寫方法8. 詳解JAVA 強(qiáng)引用9. python之cur.fetchall與cur.fetchone提取數(shù)據(jù)并統(tǒng)計(jì)處理操作10. JSP之表單提交get和post的區(qū)別詳解及實(shí)例
