0

我正在尝试学习如何使用 Vue 和 Webpack 4 创建多页应用程序。主要原因是服务器不是无状态的,由于权限和受保护路由的复杂性,我需要服务器来处理路由。

但是,我想使用 Vue.js 来利用单文件组件的强大功能来创建可重用和可维护的代码。我了解如何修改我的 wepack.config.js 以设置多个入口点,并且我假设我将提供一个不同的包,该包将被注入到单个 index.html 中,但有些地方我开始不清楚.

我将如何使用 Vue.js 处理这个问题?需要说明的是,我没有使用 Vue CLI,我想使用单文件组件来设计前端。一个简单的项目骨架/样板代码将不胜感激,并强调配置。

我的主要入口点(main.js)

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import $ from 'jquery';
import 'bootstrap/dist/js/bootstrap.js';
import 'bootstrap/dist/css/bootstrap.min.css';
import '@fortawesome/fontawesome-free/js/all.js'

Vue.config.productionTip = false;

new Vue({
  el: '#app',
  router,
  render: h => h(App),
});

webpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

module.exports = {
  entry: './src/main.js',
  module: {
    rules: [
      { test: /\.js$/, use: 'babel-loader', exclude: '/node_modules'},
      { test: /\.vue$/, use: 'vue-loader' },
      { test: /\.css$/, use: ['vue-style-loader', 'css-loader']},
      //{ test: /\.(png|svg|jpg|gif)$/, use: 'file-loader'},
    ]
  },
  devServer: {
    open: true,
    hot: true,
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [
    new HtmlWebpackPlugin({template: './src/index.html'}),
    new VueLoaderPlugin(),
    //new webpack.HotModuleReplacementPlugin(),
    new CopyPlugin([{from: 'src/images', to: 'images'}])
  ]
};

4

0 回答 0