html [Vue] Vue + Webpack起手式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html [Vue] Vue + Webpack起手式相关的知识,希望对你有一定的参考价值。

const path = require('path')
const webpack = require('webpack')

module.exports = {
  entry: path.join(__dirname, 'src', 'main'),
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/dist'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      }
    ]
  },
  resolve: {
    extensions: ['.js', '.vue'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ]
}
{
  "name": "vuecli-andy",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "cross-env": "^5.0.0",
    "css-loader": "^0.28.1",
    "file-loader": "^0.11.1",
    "style-loader": "^0.17.0",
    "url-loader": "^0.5.8",
    "vue-hot-reload-api": "^2.1.0",
    "vue-loader": "^12.0.4",
    "webpack": "^2.5.1",
    "webpack-dev-server": "^2.4.5",
    "webpack-merge": "^4.1.0"
  }
}
/* eslint no-unused-vars: "vm" */
import Vue from 'vue'
import App from './app.vue'

new Vue({
  el: '#app',
  components: { App }
})
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Vue JS with Webpack</title>
</head>
<body>
  <div id="app">
    <app></app>
  </div>
  <script src="dist/bundle.js"></script>
</body>
</html>
<!-- app.vue -->

<template lang="html">
  <div class="message">
    {{ message }}
    {{ ok }}
  </div>
</template>

<script>
export default {
  data () {
    return {
      message: 'Helo, Vue.js 2.0',
      ok: 'Setup up is OK!!!!'
    }
  }
}
</script>

<style lang="css">
.message {
  color: pink;
  font-size: 1.4em;
}
</style>

以上是关于html [Vue] Vue + Webpack起手式的主要内容,如果未能解决你的问题,请参考以下文章

使用vue2.x+webpack+vuex+sass+axios+elementUI等快速搭建前端项目框架

带有 webpack require() 的 Vue.js 动态图像 src 不起作用

Vue webpack动态导入需要不起作用

VUE.JS 通过 webpack-simple 中的 axios 从 url 接收一个 json 文件

html [Vue] Vue + Webpack起手式

让webpack+vue-cil项目不再自动打开浏览器的方法