const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const webpack = require('webpack'); const SpeedMeasurePlugin = require('speed-measure-webpack-plugin'); const smp = new SpeedMeasurePlugin(); const proxyHost = { localhost: 'http://192.168.16.252:8093', //链接本地调试 development: 'https://arthas.mttop.cn', production: 'https://mt.mttop.cn', feature: 'http://192.168.8.108:8096', }; const proxy_env = proxyHost[process.env.PROXY_ENV]; const config = { mode: 'development', entry: './src/test/index.tsx', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), }, resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'], alias: { '@': path.resolve(__dirname, 'src'), }, }, module: { rules: [ { test: /\.tsx?$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', }, { loader: 'ts-loader', }, ], }, { test: /\.jsx?$/, exclude: /node_modules/, use: { loader: 'babel-loader', }, }, { test: /\.less$/, include: /node_modules\/antd/, // antd中的样式 use: [ 'style-loader', 'css-loader', { loader: 'less-loader', options: { javascriptEnabled: true, }, }, ], }, { test: /\.less$/, exclude: /node_modules/, // 项目中的样式 use: [ 'style-loader', { loader: 'css-loader', options: { modules: true, }, }, { loader: 'less-loader', options: { modules: true, }, }, ], }, { test: /\.css$/, // 外部引入的react-virtualized/styles.css use: [ 'style-loader', { loader: 'css-loader', }, ], }, { test: /\.(jpg|png|gif)$/, use: { loader: 'url-loader', options: { limit: 10240, // 超过10kb打包为图片 }, }, }, ], }, plugins: [ new webpack.ProgressPlugin(), new CleanWebpackPlugin(), new HtmlWebpackPlugin({ filename: 'index.html', template: './src/index.html', }), ], devServer: { proxy: { '/nodeApi': { target: `${proxy_env}${process.env.PROXY_ENV !== 'localhost' ? '/nodeApi' : ''}`, changeOrigin: true, pathRewrite: { '^/nodeApi': '' }, }, '/ws': { target: `${proxyHost[process.env.BUILD_ENV]}/cms`, changeOrigin: true, pathRewrite: { '^/ws': '' }, ws: true, }, '/adminApi': { target: `${proxy_env}${process.env.PROXY_ENV !== 'localhost' ? '/adminApi' : ''}`, changeOrigin: true, pathRewrite: { '^/adminApi': '' }, }, '/loginApi': { target: `${proxy_env}${process.env.PROXY_ENV !== 'localhost' ? '/loginApi' : ''}`, changeOrigin: true, pathRewrite: { '^/loginApi': '' }, }, '/crmApi': { target: `${proxy_env}${process.env.PROXY_ENV !== 'localhost' ? '/crmApi' : ''}`, changeOrigin: true, pathRewrite: { '^/crmApi': '' }, }, '/approvalApi': { target: `${proxy_env}${process.env.PROXY_ENV !== 'localhost' ? '/approvalApi' : ''}`, changeOrigin: true, pathRewrite: { '^/approvalApi': '' }, }, }, contentBase: path.join(__dirname, 'dist'), compress: false, hot: true, port: 9000, }, }; module.exports = smp.wrap(config);