Code Monkey home page Code Monkey logo

vue-vuerouter-webpack's Introduction

#vue-vueRouter-webpack

本项目可以帮你快速搭建一个基于Vue的单页面富应用,但这并不意味着是最佳实践,所有的目录结构和webpack配置都可以根据自己需要修改

##教程

可以访问下面的链接来查看系列教程

Vue+Webpack开发可复用的单页面富应用教程(配置篇)

Vue+Webpack开发可复用的单页面富应用教程(组件篇)

Vue+Webpack开发可复用的单页面富应用教程(技巧篇)

Vue+Webpack使用规范 ##目录结构

│  .gitignore          # 忽略文件,比如 node_modules
│  package.json        # 项目配置
│  README.md           # 项目说明
│  index.html          # 首页
│
├─ webpack.base.config.js         # webpack 基础配置
├─ webpack.dev.config.js          # webpack 开发配置
├─ webpack.prod.config.js         # webpack 生产配置
│
│
├─node_modules
│
├─dist                 # 打包完的文件会自动放在这里
│
└─src
    ├─ main.js         # 启动配置
    │
    ├─ router.js       # 路由配置
    │
    ├─components       # 组件
    │       │
    │       └─ app.vue # 入口组件,内含路由和公共部分
    │
    ├─views            # 视图(即路由)
    │
    ├─directives       # 自定义指令
    │
    ├─filters          # 自定义过滤器
    │
    ├─config           # 放置一些配置文件
    │
    ├─libs             # 放置一些工具函数
    │
    ├─images           # 放置图片
    │
    ├─styles           # 放置css
    │    │
    │    ├─ common.css # 通用css
    │    │
    │    └─ reset.css  # 页面初始化css
    │
    ├─fonts            # 放置iconfont字体
    │
    │
    └─template         # 放置html模板,webpack依赖此文件生成所需的html
         │
         │
         └─ index.ejs # 默认的html模板

##说明 目前已将css(使用@import的和.vue内style的)样式都独立抽离为main.css文件,如果想按需加载,可以将webpack.base.js内的如下代码注释

vue: {
    loaders: {
        css: ExtractTextPlugin.extract(
            "style-loader",
            "css-loader?sourceMap",
            {
                publicPath: "../dist/"
            }
        )
    }
}

new ExtractTextPlugin("[name].css",{ allChunks : true,resolve : ['modules'] }),

#如何使用

##说明

目前已将打包后的dist目录和webpack生成的index.html和index_prod.html加入了git忽略列表,如果不需要这样做,请修改。 目前分开发环境和生产环境,分别对应webpack.dev.config.js和webpack.prod.config.js可以根据自己需要来调整相关webpack配置,比如添加灰度环境配置。 目前的开发环境文件使用默认命名,生产环境使用带hash值的命名,可根据自己需要修改,但不建议修改本地环境为带hash的。 入口的html文件模板在src/template/index.ejs内,可自行修改

##安装

// 安装前请先确保已安装node和npm
// 需要提前在全局安装webpack和webpack-dev-server,如果已安装请忽略
npm install webpack -g
npm install webpack-dev-server -g

// 安装成功后,再安装依赖
npm install

##运行 ####开发环境

// 注意首次使用需要执行下面的init命令来生成入口html文件,以后不用再执行
npm run init
npm run dev

####生产环境(打包)

npm run build

####访问 在浏览器地址栏输入http://127.0.0.1:8080

#更新

##2016.10.3

  • package支持了less和sass

##2016.9.11

  • 修复打包到生产环境时,index_prod.html文件的html结构错误的bug

##2016.8.22

  • 全部改为ES2015
  • 抽离路由配置为router.js
  • 将routers目录重命名为views
  • vue配置默认支持less和sass

vue-vuerouter-webpack's People

Contributors

icarusion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-vuerouter-webpack's Issues

可以新建router.js文件管理路由,并将routers文件夹命名为views

建议:

  1. 可以新建router.js文件管理路由
    • 目前路由是写在main.js中,这样伴随着项目的扩展会导致main.js的可读性变差,可以新建router.js文件管理路由导出对象,main.js引入然后map下
  2. 可以将routers文件夹命名为views
    • routers第一感觉是路由,但是打开文件夹发现里边是vue文件,才明白是页面,有点绕

最后表示感谢,作者的文章很好!

Can you help me?

When i execute 'npm run dev' command,error....

npm-debug.log

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]predev: [email protected]
6 silly lifecycle [email protected]
predev: no script for predev, continuing
7 info lifecycle [email protected]dev: [email protected]
8 verbose lifecycle [email protected]
dev: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]dev: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Program Files\nodejs\node_modules\vue-vueRouter-webpack-master\node_modules.bin;C:\Program Files\nodejs\node_modules.bin;C:\Users\somebody\AppData\Roaming\npm;C:\Program Files\nodejs;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files (x86)\Autodesk\Backburner;F:\Program Files\Git\cmd;F:\Program Files\MATLAB\R2016b\runtime\win64;F:\Program Files\MATLAB\R2016b\bin;F:\Program Files\MATLAB\R2016b\polyspace\bin;C:\Program Files\dotnet;C:\Program Files\nodejs;C:\Users\somebody\AppData\Local\Microsoft\WindowsApps;F:\Program Files\Microsoft\Visual Studio Code\bin;C:\Users\somebody\AppData\Local\Programs\Python\Python35;C:\Users\somebody\AppData\Roaming\npm
10 verbose lifecycle [email protected]
dev: CWD: C:\Program Files\nodejs\node_modules\vue-vueRouter-webpack-master
11 silly lifecycle [email protected]dev: Args: [ '/d /s /c',
11 silly lifecycle 'webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js' ]
12 silly lifecycle [email protected]
dev: Returned: code: 1 signal: null
13 info lifecycle [email protected]~dev: Failed to exec dev script
14 verbose stack Error: [email protected] dev: webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
14 verbose stack Exit status 1
14 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:877:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid [email protected]
16 verbose cwd C:\Program Files\nodejs\node_modules\vue-vueRouter-webpack-master
17 error Windows_NT 10.0.15031
18 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev"
19 error node v6.10.0
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error [email protected] dev: webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
22 error Exit status 1
23 error Failed at the [email protected] dev script 'webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the vue-vue-router-webpack package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs vue-vue-router-webpack
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls vue-vue-router-webpack
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

webpack

请问一下运行webpack的时候为什么总是出现这个output filename not configured
如何解决啊

I came up with an error when I run the script: npm run dev

My environment:

npm :5.0.3
node:v7.8.0
OS: macOS 10.12

The error information:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 configuration has an unknown property 'vue'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
   For typos: please correct them.
   For loader options: webpack 2 no longer allows custom properties in configuration.
     Loaders should be updated to allow passing options via loader options in module.rules.
     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
     plugins: [
       new webpack.LoaderOptionsPlugin({
         // test: /\.xxx$/, // may apply this only for some modules
         options: {
           vue: ...
         }
       })
     ]
configuration.resolve.extensions[0] should not be empty.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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!     /Users/achao_zju/.npm/_logs/2017-07-22T15_24_40_140Z-debug.log

Could anyone help me?

npm run dev 报错

前面都可以,到这里就错了。
`
$ npm run dev

[email protected] dev E:\git\vue-vueRouter-webpack
webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js

module.js:442
throw err;
^

Error: Cannot find module 'webpack'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (D:\nodejs\node_modules\webpack-dev-server\bin\webpack-dev-server.js:17:15)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\nodejs\node.exe" "D:\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev"
npm ERR! node v6.3.1
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vue-vue-router-webpack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vue-vue-router-webpack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls vue-vue-router-webpack
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! E:\git\vue-vueRouter-webpack\npm-debug.log
`

npm run dev报错了

前面步骤都对了,最后npm run dev报错

npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v4.4.7
npm ERR! npm v2.15.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js'.
npm ERR! This is most likely a problem with the vue-fist package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack-dev-server --inline --hot --compress --history-api-fallback --config webpack.dev.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vue-fist
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls vue-fist
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/tangjuan/vue-vueRouter-webpack/npm-debug.log
tangjuandeMacBook-Pro:vue-vueRouter-webpack tangjuan$ npm run dev

npm run dev的时候dist里没有文件呢?

遇到个麻烦事,需要把前端和php组合到一起,不然session没法传递,但是我看监视模式下,dist里没有打包出来的文件呢,这样通过php那边的http就读取不到文件了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.