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

好了本文內容全部結束,感謝您的閱讀希望能幫助到你

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章