Webpack构建vue项目-记录

一,安装node.js

https://nodejs.org/en/

二,打开Node.js command prompt

三,执行命令

1.安装vue-cli

C:\deve\workspace\myproject>npm install -g vue-cli
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
C:\Users\Dong\AppData\Roaming\npm\vue-init -> C:\Users\Dong\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-init
C:\Users\Dong\AppData\Roaming\npm\vue -> C:\Users\Dong\AppData\Roaming\npm\node_modules\vue-cli\bin\vue
C:\Users\Dong\AppData\Roaming\npm\vue-list -> C:\Users\Dong\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-list
+ vue-cli@2.9.6
added 239 packages from 206 contributors in 32.501s

2.修改chromedriver配置

C:\deve\workspace\myproject>npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver

> chromedriver@75.0.0 install C:\deve\workspace\myproject\node_modules\chromedriver
> node install.js

Current existing ChromeDriver binary is unavailable, proceding with download and extraction.
Downloading from file:  http://cdn.npm.taobao.org/dist/chromedriver/75.0.3770.8/chromedriver_win32.zip
Saving to file: C:\Users\Dong\AppData\Local\Temp\75.0.3770.8\chromedriver\chromedriver_win32.zip
Received 783K...
Received 1600K...
Received 2387K...
Received 3179K...
Received 3961K...
Received 4549K total.
Extracting zip contents
Copying to target path C:\deve\workspace\myproject\node_modules\chromedriver\lib\chromedriver
Done. ChromeDriver binary available at C:\deve\workspace\myproject\node_modules\chromedriver\lib\chromedriver\chromedriver.exe
npm WARN saveError ENOENT: no such file or directory, open 'C:\deve\workspace\myproject\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\deve\workspace\myproject\package.json'
npm WARN myproject No description
npm WARN myproject No repository field.
npm WARN myproject No README data
npm WARN myproject No license field.

+ chromedriver@75.0.0
added 28 packages from 56 contributors and audited 1992 packages in 11.318s
found 0 vulnerabilities

3.创建项目名为my-project的项目

C:\deve\workspace\myproject>vue init webpack my-project

'git' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
? Project name my-project
? Project description A Vue.js project
? Author sagitarioo
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Pick a test runner jest
? Setup e2e tests with Nightwatch? Yes
? Should we run `npm install` for you after the project has been created? (recommended) npm

   vue-cli · Generated "my-project".

# Installing project dependencies ...

# Project initialization finished!
# ========================

To get started:

  cd my-project
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack

4.启动

C:\deve\workspace\myproject>cd my-project

C:\deve\workspace\myproject\my-project>npm install
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.

audited 31720 packages in 14.387s
found 84 vulnerabilities (65 low, 8 moderate, 10 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

C:\deve\workspace\myproject\my-project>npm run dev

> my-project@1.0.0 dev C:\deve\workspace\myproject\my-project
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

 12% building modules 24/31 modules 7 active ...pace\myproject\my-project\src\App.vue{ parser: "babylon" } is deprecated; we now treat it as { parser: "bab 95% emitting

 DONE  Compiled successfully in 7514ms                                                                       11:28:18 PM

 I  Your application is running here: http://localhost:8080 

5.打开浏览器

配置vue图形界面

vue ui 是3.0才推出的版本,我使用的时候最新稳定版为2.9.6,所以没有这个功能,故要安装最新的vue

C:\deve\workspace\myproject>npm install -g @vue/cli
C:\Users\Dong\AppData\Roaming\npm\vue -> C:\Users\Dong\AppData\Roaming\npm\node_modules\@vue\cli\bin\vue.js

> core-js@3.1.3 postinstall C:\Users\Dong\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js-pure@3.1.3 postinstall C:\Users\Dong\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\core-js-pure
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> protobufjs@6.8.8 postinstall C:\Users\Dong\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\protobufjs
> node scripts/postinstall


> nodemon@1.19.1 postinstall C:\Users\Dong\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\nodemon
> node bin/postinstall || exit 0

Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\@vue\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @vue/cli@3.8.3
added 809 packages from 541 contributors in 105.459s

启动vue ui

C:\deve\workspace\myproject>vue ui
?  Starting GUI...
?  Ready on http://localhost:8000

其他 

第一次尝试没有使用官方脚手架,是参考的这篇文章:随我来基于webpack构建一个简易的vue脚手架 (webpack系列二) - 努力学会微笑 - segmentfault

按照该教程的步骤来搭建。由于插件版本问题,会报一个错:

C:\deve\vue-cli\vues>npm run dev

> vues@1.0.0 dev C:\deve\vue-cli\vues
> webpack-dev-server --open --hot

C:\deve\vue-cli\vues\webpack.config.js:30
    new CleanWebpackPlugin(['dist']),  // 告诉清理插件的目录
    ^

TypeError: CleanWebpackPlugin is not a constructor
    at Object.<anonymous> (C:\deve\vue-cli\vues\webpack.config.js:30:5)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at WEBPACK_OPTIONS (C:\deve\vue-cli\vues\node_modules\webpack-cli\bin\utils\convert-argv.js:116:13)
    at requireConfig (C:\deve\vue-cli\vues\node_modules\webpack-cli\bin\utils\convert-argv.js:118:6)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vues@1.0.0 dev: `webpack-dev-server --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vues@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Dong\AppData\Roaming\npm-cache\_logs\2019-06-13T14_14_25_609Z-debug.log

需要修改位置:

const { CleanWebpackPlugin } = require('clean-webpack-plugin');  // 清理构建目录下的文件

plugins:[
    new CleanWebpackPlugin(),  // 告诉清理插件的目录
],

运行效果:

代码可参考:https://github.com/Sagitarioo/Personal/tree/master/study

由于node_modules文件夹中的小文件太多,故没有同步。

目录结构:

vues
├─node_modules
│  ├─.bin
│  ├─@types
│  ├─@vue
│  └─...
├─src
│  ├─app.vue
│  └─index.js
├─index.html
├─package.json
└─webpack.config.js

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值