wujingjing
2025-02-17 0f01c4bbce19fa8489a4e835c83cb9415549f681
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const path = require('path');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
// 统一路径解析
function resolve(dir) {
  return path.resolve(__dirname, dir);
}
 
// 包括生产和开发的环境配置信息
module.exports = {
  webpack: {
    // webpack的resolve配置
    resolve: {
      // 用于配置webpack在尝试过程中用到的后缀列表
      extensions: [
        '.js',
        '.jsx',
        '.ts',
        '.tsx',
        '.esm.js',
        '.umd.js',
        '.min.js',
        '.json',
        '.mjs'
      ],
      alias: {
        '@': resolve('src')
        // $function: resolve('src/function'),
        // $utils: resolve('src/utils'),
      }
      // conditionNames: ['require']
    },
    createDeclaration: false, // 打包时是否创建ts声明文件
    ignoreNodeModules: false, // 打包时是否忽略 node_modules
    allowList: [], // ignoreNodeModules为true时生效
    externals: ['react/jsx-runtime'],
    projectDir: ['src'],
    template: resolve('./src/index.html'), // 使用自己的html模板
    // cssLoaderUrl: true,
    // cssLoaderUrlDir: 'editor/fontawesome-free',
    moduleRules: [], // 用于配置自定义loaders
    plugins: [] // 用于配置自定义plugins
  },
  dev: {
    entry: {
      // 本地调试模式的入口
      index: './src/index.tsx'
    },
    // 用于开启本地调试模式的相关配置信息
    NODE_ENV: 'development',
    ignoreNodeModules: false, // 打包时是否忽略 node_modules
    port: 80,
    autoOpenBrowser: true,
    assetsPublicPath: '/', // 设置静态资源的引用路径(根域名+路径)
    assetsSubDirectory: '',
    hostname: 'localhost',
    cssSourceMap: false,
    closeHotReload: false, // 是否关闭热更新
    closeEditorClient: true, // 是否关闭自动注入editor
    proxyTable: {
      /**
       * 将含有'/apiTest'路径的api代理到'http://api-test.com.cn'上,
       * 详细使用见 https://www.webpackjs.com/configuration/dev-server/#devserver-proxy
       */
      '/apiTest': {
        target: 'http://api-test.com.cn', // 不支持跨域的接口根地址
        ws: true,
        changeOrigin: true
      }
    }
  },
  build: {
    entry: {
      // webpack构建入口
      index: './src/index.tsx'
      // editor:  './src/mobile.tsx'
    },
    // 用于构建生产环境代码的相关配置信息
    NODE_ENV: 'production',
    assetsRoot: resolve('./amis-editor'), // 打包后的文件绝对路径(物理路径)
    // 网络请求路径(可能也需要修改 index.html,其中有两个静态资源需要修改位置)
    assetsPublicPath: '/amis-editor/', // 设置静态资源的引用路径(根域名+路径)
    assetsSubDirectory: '', // 资源引用二级路径
    productionSourceMap: false,
    productionGzip: false,
    productionGzipExtensions: ['js', 'css', 'json'],
    plugins: [new MonacoWebpackPlugin()],
    bundleAnalyzerReport: false
  }
};