Quellcode durchsuchen

解决element报错

cynthia-qin vor 1 Monat
Ursprung
Commit
0917767a6d
1 geänderte Dateien mit 34 neuen und 32 gelöschten Zeilen
  1. 34 32
      webpack.config.js

+ 34 - 32
webpack.config.js

@@ -1,15 +1,19 @@
 const path = require('path');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
-const CleanWebpackPlugin = require('clean-webpack-plugin') // 清空打包目录的插件
+const CleanWebpackPlugin = require('clean-webpack-plugin');
 const MiniCssExtractPlugin = require('mini-css-extract-plugin');
 const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
 const CopyWebpackPlugin = require('copy-webpack-plugin');
-const ExtractTextPlugin = require("extract-text-webpack-plugin");
 const webpack = require('webpack');
 // const proxyHost = "http://173.18.12.195:5050";
-const proxyHost = "http://173.18.12.205:8086/healsphere";
+// const proxyHost = "http://173.18.12.205:8086/healsphere";
 // const proxyHost = "http://192.168.3.113:5050";
 // const proxyHost = "http://173.18.12.192:5050";
+const proxyHost = 'http://173.18.12.191:1388/healsphere'
+
+// 移除 extract-text-webpack-plugin 引入
+// const ExtractTextPlugin = require('extract-text-webpack-plugin');
+
 module.exports = {
   entry: {
     index: path.resolve(__dirname, 'src/js', 'index.js'),
@@ -20,7 +24,7 @@ module.exports = {
     login: path.resolve(__dirname, 'src/js', 'login.js'),
     home: path.resolve(__dirname, 'src/js', 'home.js'),
     knowledgeUpdate: path.resolve(__dirname, 'src/js', 'knowledgeUpdate.js'),
-    graphDataStatistics: path.resolve(__dirname, 'src/js', 'graphDataStatistics.js'),
+    homeMini: path.resolve(__dirname, 'src/js', 'homeMini.js'),
     vendor: 'lodash'// 多个页面所需的公共库文件,防止重复打包带入
   },
   output: {
@@ -30,11 +34,9 @@ module.exports = {
   },
   resolve: {
     extensions: [".js", ".css", ".json"],
-    alias: {
-      "vue$": "vue/dist/vue.esm.js", // 确保使用 ESM 版本
-    } //配置别名可以加快webpack查找模块的速度
+    alias: {} //配置别名可以加快webpack查找模块的速度
   },
-  plugins: [// 多入口的html文件用chunks这个参数来区分
+  plugins: [
     new HtmlWebpackPlugin({
       title: '医学知识图谱',
       template: path.resolve(__dirname, 'src/html', 'knowledgeGraph.html'),
@@ -168,6 +170,11 @@ module.exports = {
       filename: 'css/[name].css',
       chunkFilename: '[id].css'
     }),
+    // 移除 ExtractTextPlugin 实例
+    // new ExtractTextPlugin({
+    //   filename: 'css/[name].css',
+    //   allChunks: true
+    // }),
     new webpack.ProvidePlugin({
       $: 'jquery',
       jQuery: 'jquery',
@@ -175,7 +182,7 @@ module.exports = {
     }),
     new webpack.HotModuleReplacementPlugin(),
     new CleanWebpackPlugin(),
-    new ExtractTextPlugin("stylesheets/[name].css"),
+    // new ExtractTextPlugin("stylesheets/[name].css"),
   ],
   optimization: { //webpack4.x的最新优化配置项,用于提取公共代码
     minimizer: [
@@ -230,33 +237,28 @@ module.exports = {
       },
       {
         test: /\.css$/,
-        use: ExtractTextPlugin.extract({
-          use: [
-            // {
-            //   loader: MiniCssExtractPlugin.loader
-            // },
-            'css-loader'
-          ]
-        })
+        use: [
+          // 生产环境使用 MiniCssExtractPlugin.loader,开发环境使用 style-loader
+          process.env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
+          'css-loader'
+        ]
       },
       {
         test: /\.less$/,
-        use: ExtractTextPlugin.extract({
-          fallback: 'style-loader',
-          use: [
-            // {
-            //   loader: 'style-loader', // creates style nodes from JS strings
-            // },
-            {
-              loader: 'css-loader', // translates CSS into CommonJS
-            },
-            {
-              loader: 'less-loader', // compiles Less to CSS
-            },
-          ],
-        })
-
+        use: [
+          process.env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : 'style-loader',
+          'css-loader',
+          'less-loader'
+        ]
       },
+      // 移除使用 extract-text-webpack-plugin 的规则
+      // {
+      //   test: /\.css$/,
+      //   use: ExtractTextPlugin.extract({
+      //     fallback: 'style-loader',
+      //     use: 'css-loader'
+      //   })
+      // },
       {
         test: /\.(png|jpg|jpeg|gif|svg)$/,
         use: {