1.0.6 • Published 9 months ago

fast-integration-webpack-plugin v1.0.6

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
9 months ago

FAST Integration Webpack Plugin

包含2个功能 1. 集成天眼探针 2. 上传sourcemap

版本日志

1.0.6

  1. 调整hashKey的校验和处理方式(避免错误填写导致API失败)

1.0.5

  1. 修复使用集成功能时环境参数拼接错误

1.0.4

  1. 额外导出一个FastIntegrationWebpackPlugin(需要修改引用方式)
  2. 修复在容器中node方式调用上传sourcemap时,配置了deleteSourcemapAfterUpload时报错的问题

1.0.3

  1. 新增一个函数调用的方式
  2. webpack方式不再支持extra_dir

插件功能

fast-integration-webpack-plugin是基于webpack4开发的webpack插件,为天眼探针定位上报异常在源代码中的确切位置提供source文件和map文件

在webpack中作为插件使用,需要开启项目的sourceMap文件生成选项(webpack的devtool配置),插件会根据输出目录递归搜索 .js文件和.js.map文件 .css.map文件

其中,.js文件和.js.map文件会上传到天眼 .css.map文件不会上传,根据插件配置项 可以决定插件是否删除输出目录中的 .js.map文件和.css.map文件

提示:避免在开发环境使用该插件,否则由于上传文件可能导致热加载时间过长,在生产环境再启用该插件

配置项

配置字段类型说明是否必填默认值
hashKeystring项目唯一标识-
enableTrackerIntergrationboolean是否启用探针集成功能false
trackerEnvstring探针集成环境prod
htmlEntryPathstring[]探针脚本注入的入口html文件路径'index.html'
enableSourcemapUploadboolean是否上传sourcemaptrue
buildingSourcemapUploadPrefixstring上传sourcemap的路径附加前缀-
deleteSourcemapAfterUploadboolean是否在输出阶段删除.js.map和.css.map文件true

使用

使用npm安装

npm i fast-integration-webpack-plugin -D

使用yarn安装

yarn add fast-integration-webpack-plugin

以webpack插件形式使用

注意,作为webpack插件使用时,不再支持追加目录,仅上传构建过程中产生的文件,如果需要同时处理多个目录下的上传,请以函数形式调用的方式使用

在webpack中

import path from 'path'; // 需要额外上传某个文件
plugins: [
    new FastIntegrationWebpackPlugin({
      hashKey: '这里使用平台上数据接入步骤中复制出来的即可',
      // 探针集成的相关参数
      enableTrackerIntergration: true,
      htmlEntryPath: ['index.html'],
      // sourcemap上传相关参数
      enableSourcemapUpload: true,
      deleteSourcemapAfterUpload: true
    })
]

在umi中 config.js

import FastIntegrationWebpackPlugin from 'fast-integration-webpack-plugin';
import path from 'path';
export default {
  devtool: 'hidden-source-map', // 开启sourcemap
  chainWebpack: config => { // 使用fast-integration-webpack-plugin插件
    config
    .plugin('fast-integration-webpack-plugin') 
    .use(new FastIntegrationWebpackPlugin({
      hashKey: '这里使用平台上数据接入步骤中复制出来的即可',
      // 探针集成的相关参数
      enableTrackerIntergration: true,
      htmlEntryPath: ['index.html'],
      // sourcemap上传相关参数
      enableSourcemapUpload: true,
      buildingSourcemapUploadPrefix: 'app',
      deleteSourcemapAfterUpload: true
    }))
  },
  plugins: [
    // ref: https://umijs.org/plugin/umi-plugin-react.html
    ['umi-plugin-react', {
      ...
    }]
  ],
  hash: true,
  targets: {
    ie: 9
  },
  // 路由配置
  routes: pageRoutes,
  // ANTD主题配色
  theme: {
  },
  // Webpack Configuration
  proxy: {
  }
}

以函数形式调用

该模式下独有的配置项 | 配置 | 字段类型 | 说明 | 是否必填 | 默认值 | | :--- | :--- | :--- | :--- | :--- | | uploadDir | (DirType|string)[] | 待上传的目录的绝对路径 | 是 | - |

DirType | 字段 | 字段类型 | 说明 | | :--- | :--- | :--- | | path | string | 目录绝对路径(path.resolve(__dirname, "{路径}")) | | uploadPrefix | string | 上传目标目录的附加前缀 |

const { uploadSourcemapToFast } = require('fast-integration-webpack-plugin');

uploadSourcemapToFast({
  hashKey: 'xxxxx',
  uploadDir: [
    { path: path.resolve(__dirname, './gcxt_dist'), uploadPrefix: 'applications/gxct' },
    path.resolve(__dirname, './dist')
  ],
  deleteSourcemapAfterUpload: true
});

上传时间

上传时间不定,根据当前网络状况决定,存在的文件不会上传(根据文件路径与名称区分,请开启文件名hash)。

注意事项

  1. 配置devtool生成sourcemap文件时,如果您的项目需要保留sourcemap文件,那么推荐使用 'source-map' 模式,该模式为 bundle 添加了一个引用注释,以便开发工具知道在哪里可以找到它。 如果您的项目不需要保留生产的sourcemap文件,推荐使用 'hidden-source-map' 模式,与source-map 相同,但不会为 bundle 添加引用注释。

  2. 如果您的项目将css、less、scss文件打包入您的js文件时,请在相关loader中关闭您css、less、scss相关文件的sourcemap生成配置。以防止生成的map文件一并打包入您的js文件中,导致js文件大小超过预期。

例:

{
  loader: 'style-loader',
  options: {
    sourceMap: false
  }
}
  1. 由于node对进程的内存分配有默认设置,32位系统 node默认分配内存 0.7g左右,64位系统默认分配内存1.4g左右, 如果项目复杂,在开启souremap生成选项时,打包的时候,可能出现内存不足导致打包失败的情况

例:

<--- Last few GCs --->

[70041:0x103800000]   112100 ms: Mark-sweep 1049.8 (1273.7) -> 1049.7 (1214.2) MB, 427.1 / 0.0 ms  (average mu = 0.618, current mu = 0.000) last resort GC in old space requested
[70041:0x103800000]   112510 ms: Mark-sweep 1049.7 (1214.2) -> 1049.7 (1192.2) MB, 410.3 / 0.0 ms  (average mu = 0.447, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x36295d35be3d]
Security context: 0x0280a0d9e6e1 <JSObject>
    1: byteLength(aka byteLength) [0x280057866f1] [buffer.js:531] [bytecode=0x280f3e290c1 offset=204](this=0x0280cf7826f1 <undefined>,string=0x028037c8a291 <Very long string[190258200]>,encoding=0x0280a0dbd819 <String[4]: utf8>)
    2: arguments adaptor frame: 3->2
    3: fromString(aka fromString) [0x2800579d2d9] [buffer.js:342] [bytecode=0x280f3e278e1 offs...

解决方案:

配置打包命令时,修改node进程占用内存的大小 --max-old-space-size

例:

package.json

"scripts": {
    "build": " node --max-old-space-size=4096 ./scripts/build.js",
  },
1.0.6

9 months ago

1.0.5

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.3-r1

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago