• webpack手动配置Vue项目


    项目目录:

     创建步骤:

    (1)创建main.js(入口文件),index.html(项目首页),App.vue(根组件),webpack.config.js(webpack配置文件)

    (2)安装项目依赖包npm install xxx

    webpack有关:webpack、webpack-dev-server、webpack-cli、html-webpack-plugin(用于运行项目后在dist文件生成编译后的*.html文件)

    vue有关:vue、vue-loader、vue-html-loader、vue-style-loader、vue-template-compiler

    es6:babel-core、babel-loader、babel-plugin-transform-runtime、babel-preset-es2015、babel-runtime

    css:css-loader

    (3)package.json文件

    {
      "name": "myVue",
      "version": "1.0.0",
      "description": "",
      "main": "main.js",
      "scripts": {
        "dev": "webpack-dev-server --inline --hot",
        "build": "webpack"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        "vue": "^2.6.11",
        "vue-template-compiler": "^2.6.11",
        "webpack": "^4.43.0",
        "webpack-dev-server": "^3.10.3"
      },
      "devDependencies": {
        "babel-core": "^6.26.3",
        "babel-loader": "^7.1.5",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-preset-es2015": "^6.24.1",
        "babel-runtime": "^6.26.0",
        "css-loader": "^3.5.3",
        "html-webpack-plugin": "^4.2.1",
        "vue-hot-reload-api": "^2.3.4",
        "vue-html-loader": "^1.2.4",
        "vue-loader": "^15.9.1",
        "vue-style-loader": "^4.1.2",
        "webpack-cli": "^3.3.11"
      }
    }

    main.js

    import Vue from 'vue';
    import App from './App.vue';
    
    new Vue({
        el:'#app',
        render:function (creater) {
            return creater(App);
        }
    })

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>vue程序启动</title>
    </head>
    <body>
    <div id="app"></div>
    </body>
    </html>

    App.vue

    <template>
        <div>Hello World</div>
    </template>
    
    <script>
    </script>
    
    <style scoped>
    </style>

    webpack.config.js

    const VueLoaderPlugin = require('vue-loader/lib/plugin');
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    module.exports = {
        entry: {main: './main.js'},
        output: {
            path: __dirname,
            filename: './build.js'
        },
        module: {
            rules: [
                { test: /.vue$/, loader: 'vue-loader' },
                {
                    test:/.js$/,
                    loader: 'babel-loader',
                    exclude: /node_modules/,
                    options: {
                        presets: ['es2015'],
                        plugins: ['transform-runtime']
                    }
                }
            ]
        },
        plugins: [
            new VueLoaderPlugin(),
            new HtmlWebpackPlugin({
                template:'./index.html',
            })
        ]
    }
  • 相关阅读:
    QDUOJ 来自xjy的签到题(bfs+状压dp)
    HDU
    【原创+整理】线程同步之详解自旋锁
    【原创】浅说windows下的中断请求级IRQL
    【原创】驱动开发中Memory read error导致的蓝屏问题
    [转&精]IO_STACK_LOCATION与IRP的一点笔记
    【原创】《windows驱动开发技术详解》第4章实验总结二
    【原创】《windows驱动开发技术详解》第4章实验总结一
    【转载】LINUX 和 WINDOWS 内核的区别
    【原创】Windows服务管家婆之Service Control Manager
  • 原文地址:https://www.cnblogs.com/psy-fei/p/12805571.html
Copyright © 2020-2023  润新知