Vue.js has been used as a major development framework in recent days on projects, and is used with Webpack for ease of release. The CSS framework uses the VUE-STRAP (Vue has encapsulated the bootstrap control)
This article mainly summarizes the concrete construction process, and some problems encountered in the way to solve
The main tools to use
- Vue
- Webpack
- Vue-strap
- Vue-router
Build Step 1. First establish the directory structure of the project
- demo_project/
- dist/
webpack生成的文件
- src/
源代码文件
- img/
图片文件
- css/
css文件
- js/
js文件
- components/
定义的vue组件
- views/
视图文件,其实也是vue组件
- Webpack.config.js
webpack配置文件
2. Installing Vue and Webpack
# enter into the Demo_project directory NPM Install Vue--save NPM Install Webpack--save
|
3. Add the Webpack configuration file
Module.exports = { './src/index.js ', Output: { '/dist ', ' Bundle.js ' }, Module: { Loaders: [{ /\.css$/, ' Style!css ' }] } }
|
4. Add a Package.json file
# CD to Demo_project directory #跟着步骤一步一步的完成
|
The last file generated is package.json
as follows
{ "Name":"Vuedemo", "Version":"1.0.0", "description":"A Vue demo with Webpack", "Main":"Webpack.config.js", "Dependencies": { " vue": "^1.0.4", " webpack": "^1.12.2" }, "Devdependencies": {}, "Scripts": { "test": "echo \" Error:no test specified\ "&& exit 1", "Start":"Webpack--color--progress" //Note that this was added after I generated it. Used to perform webpack. If Webpack installed in the global can be directly action Webpack to package }, " Author": "Frank" }
|
5. Add HTML and JS entry files
<!--src/index.html-- <HTML> < HEAD> <meta charset= "Utf-8"; </HEAD> < Body> <script type= "Text/javascript" src=</SCRIPT> </BODY> |
/* Src/index.js */ document.write (' hello. Webpack runs ok! ')
|
6. Verify that the Webpack is successful
Open the index.html in the browser. See hello. webpack runs ok!
that the Webpack is running successfully.
This is followed by the Vue file that was loaded with Vue's loader. Write it again next time.
Then install Vue-loader.
7. Installing Vue-loader
Installation
NPM Install Vue-loader--save
|
Modifying a configuration file
Webpack.config.js loaders[ ... { Test:/\.vue$/, Loader:' vue ' } ...
|
Create a test Vue file in the views directory
<!--Hello.vue-- <Template> <STRONG>{{VUEMSG}}</Strong> </TEMPLATE> <script> module.exports = { data () { return { Vuemsg: } </SCRIPT> <style scoped> </STYLE> |
-
Introducing Vue in the Index.js file
//index.js var Vue = require ( ' vue ') var hellovue = require ( new vue ({ el: Hello:hellovue } |
Modify Index.html to join the demo's Vue node in body
... <body> <hello></hello> ... </body> ...
|
8. Test Vue
Open index.html and see红色背景的Vue hello world
Using Webpack to build the Vue development environment