初始化:css
npm init -y
安裝webpackhtml
npm install webpack webpack-cli --save-dev
安裝vuevue
npm i --save-dev vue vue-loader vue-template-compiler
安裝css的插件webpack
npm install --save-dev style-loader css-loader
npm install --save-dev file-loader
webpack.config.js 配置文件web
const path = require('path'); const VueLoaderPlugin = require('vue-loader/lib/plugin'); module.exports = { entry: './src/main.js', output:{ path: path.resolve(__dirname,'dist'), filename :'bundle.js' }, plugins:[ new VueLoaderPlugin() ], module:{ rules:[ { test: /\.vue$/, use:'vue-loader' }, { test: /\.css$/, use: [ 'vue-style-loader', 'css-loader' ] }, { test: /\.(png|svg|jpg|gif)$/, use:[ { loader:'file-loader', options: { esModule: false, } } ] } ] }, resolve:{ alias:{ "vue$":"vue/dist/vue.js" } } }
index.htmlnpm
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="app"> <p>{{msg}}</p> </div> <script src="../dist/bundle.js"></script> </body> </html>
main.jsapp
import Vue from 'vue' import app from './app.vue' var vm = new Vue({ el: '#app', data: { msg: '123' }, render:c=>c(app) })
app.vueide
<template> <div> <div class="example">{{ msg }}</div> <img src="./image/1.gif"> </div> </template> <script> export default { data () { return { msg: 'Hello world!' } } } </script> <style> .example { color: red; } </style>