var path = require('path');
const { VueLoaderPlugin } = require('vue-loader');
const ESLintPlugin = require('eslint-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        // include: [        
        //   path.resolve(__dirname, './node_modules/pc-component-v3/dist/pc-component-v3.js'),      
        // ],
        exclude: /node_modules/,
        // exclude: file => (
        //   /node_modules/.test(file) &&
        //   !/\.vue\.js/.test(file)
        // ),
      },
      {
        test: /\.css$/,
        use: (process.env.NODE_ENV === 'production') ? [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              publicPath: '../',
            },
          },
          'css-loader'] : ['style-loader', 'css-loader'],
      },
      {
        test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
        type: 'javascript/auto',
        loader: '@intlify/vue-i18n-loader',
        include: [ // Use `Rule.include` to specify the files of locale messages to be pre-compiled
          //path.resolve(__dirname, 'src/locales'),
          path.resolve(__dirname, 'client-base-v5/src/locales'),
          path.resolve(__dirname, 'client-eam-v5/src/locales'),
          path.resolve(__dirname, 'client-role-v3/src/locales'),
        ],
      },
      {
        // webpack5 通过资源模块来处理图片
        test: /\.(png|jpg|gif|svg)$/,
        type: 'asset/resource',
        parser: {
          dataUrlCondition: {
            maxSize: 10240,
          },
        },
        generator: {
          filename: './client-v5-image/[name][ext][query]',
        },
      },
      {
        test: /\.(eot|woff|woff2|ttf)$/,
        type: 'asset/resource',
        generator: {
          filename: './client-v5-font/[name].[ext]?[hash]',
        },
      },
    ],
  },
  resolve: {

    alias: {
      //   'vue$': 'vue/dist/vue.esm.js',
      '@static': path.resolve('static'),
    },
    extensions: ['*', '.js', '.vue', '.json'],
  },
  performance: {
    hints: false,
  },
  
  externals: {
    jquery: 'window.jquery',
    bootstrap: 'bootstrap',
    BootstrapDialog: 'BootstrapDialog',
    d3: 'd3',
    echarts: 'echarts',
    dayjs: 'dayjs',
    'vue': 'Vue',
    'vue-i18n': 'VueI18n',
    'vue-router': 'VueRouter',
    'vuex': 'Vuex',
    'Vuex': 'Vuex',
    'axios': 'axios',
    'sortablejs': 'Sortable'
  },
  
  plugins: [
    new VueLoaderPlugin(),
    // new ESLintPlugin({
    //   extensions: ['js', 'vue'],
    //   // 自动修复。
    //   // 自从eslint推出--fix命令后，如果觉得eslint格式化规则已经够用的话，其实也可以不用prettier了。
    //   fix: true,
    // }),
  ],
};
