🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

file-wrapper-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-wrapper-loader

a loader for wrapper the import file

0.0.4
latest
Source
npm
Version published
Weekly downloads
6
20%
Maintainers
1
Weekly downloads
 
Created
Source

file-wrapper-loader

介绍

一个用于补充代码包裹的 webpack loader,用于在依赖代码前后注入包裹代码。

安装

npm install --save-dev file-wrapper-loader

使用

举个例子,在小程序端 import tim-wx-sdk 或 cos-wx-sdk-v5 包进来,在存在 window 对象的时候会运行报错,因此我们需要在运行依赖包前将 window 对象置空。我们可以对符合条件的代码前后追加内容,以达到在特殊场景的兼容效果:

module.exports = {
    // ... 其他配置
    module: {
        rules: [
            {
                test: /tim-wx-sdk|cos-wx-sdk-v5/,
                use: [{
                    loader: 'file-wrapper-loader',
                    options: {
                        before: 'var window=undefined;', // 代码前面追加内容
                        after: ';console.log("test");', // 代码后面追加内容
                    }
                }],
                include: /node_modules/,
            },
            // ... 其他 rule
        ],
    },
}

FAQs

Package last updated on 06 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts