这里是文章模块栏目内容页
webpack 搭建vue2.7的开发环境进行前端混合开发

在做网站前端pc应用时候,采用混合的前端开发更加方便。php后台,结合模板系统,在需要数据和后台平凡互动的板块,采用vue做前端。

这种开发需求,我习惯称呼为前端混合开发。比vue单页系统,更加灵活方便。

这里是我搭建的环境配置webpack的基础,记录一下。

这是webpack.config.js

var path = require('path');
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
    entry: './app/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, '../web/futcoin/dist')
    },
    plugins: [
        // 请确保引入这个插件!
        new VueLoaderPlugin()
    ], 
    mode:"development",
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader' 
            },
            // 它会应用到普通的 `.js` 文件
            // 以及 `.vue` 文件中的 `<script>` 块
            {
                test: /\.js$/,
                loader: 'babel-loader'
              },
              // this will apply to both plain `.css` files
              // AND `<style>` blocks in `.vue` files
              {
                test: /\.css$/,
                use: [
                  'vue-style-loader',
                  'css-loader'
                ]
              }
        ]
    },
};

这是package.json文件 

{
  "name": "src",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "html-webpack-plugin": "^5.5.3",
    "uikit": "^3.16.22",
    "vue": "^2.7.14"
  },
  "devDependencies": {
    "babel-loader": "^9.1.3",
    "css-loader": "^6.8.1",
    "vue-loader": "^15.10.0",
    "vue-style-loader": "^4.1.3",
    "vue-template-compiler": "^2.7.14",
    "webpack": "^5.88.1",
    "webpack-cli": "^5.1.4"
  }
}

这是index.js

import UIkit from 'uikit';
import Icons from 'uikit/dist/js/uikit-icons';
import  Vue   from 'vue/dist/vue';
import 'uikit/dist/css/uikit.css';
import head from './head.vue'
// 加载图标插件
UIkit.use(Icons);

// 可以从导入的UIkit引用调用组件
// UIkit.notification('Hello world.');
Vue.component("vue-head", head)
var ha = new Vue({
    el:"#vue-head" 
})

采用 yarn工具安装 uikit组件,这是一款比较和bootstrap 类似的前端组件;

yarn add uikit

好了本文内容全部结束,感谢您的阅读希望能帮助到你