New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fis3-hook-node_modules

Package Overview
Dependencies
Maintainers
4
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fis3-hook-node_modules

fis3 npm support

  • 2.0.22
  • npm
  • Socket score

Version published
Weekly downloads
171
decreased by-11.86%
Maintainers
4
Weekly downloads
 
Created
Source

fis3-hook-node_modules

fis3 对npm的node_modules模块的支持

NPM version

Install

npm install fis3-hook-node_modules -g

Dependencies

  • fis3-hook-commonjs
  • mod.js

Usage

添加commonjs支持 (需要先安装fis3-hook-commonjs)

fis.hook('commonjs', {
    extList: ['.js', '.jsx', '.es', '.ts', '.tsx']
})

为node_modules文件添加针对mod.js的转换

fis.match('/{node_modules}/**.js', {
    isMod: true,
    useSameNameRequire: true
});

禁用fis3默认的fis-hook-components

fis.unhook('components')
fis.hook('node_modules')

如何使用私有npm模块

私有npm模块可以放在内网的git仓库,也可以直接使用http地址安装

直接安装tar包

npm install https://github.com/jashkenas/backbone/archive/1.3.1.tar.gz --save

从git仓库安装

npm install git+https://github.com/jashkenas/backbone --save

如何像webpack那样开发

通过这个插件, fis3已经完整实现通过 require语法加载node_modules, css, js, image等资源文件, 并支持整个npm生态圈

需要的插件

  • fis3-hook-node_modules
  • fis3-hook-commonjs
  • fis3-postpackager-loader
  • fis3-preprocessor-js-require-css
  • fis3-preprocessor-js-require-file

基本的配置

fis.hook('commonjs', {
    baseUrl: './client',
    extList: ['.js', '.jsx', '.es', '.ts', '.tsx']
});

// client为项目目录
fis.match('/{node_modules, client}/**.js', {
    isMod: true,
    useSameNameRequire: true
});

fis.match('{*.{es,jsx},/client/**.js}', {
    rExt: 'js',
    isMod: true,
    useSameNameRequire: true,
    parser: fis.plugin('babel-5.x', {}, {
        presets: ["es2015", "react", "stage-0"]
    })
});

// 用 node-sass 解析
fis.match('*.scss', {
    rExt: 'css',
    parser: [
        fis.plugin('node-sass', {
            include_paths: [
                'static/scss'
            ]
        })
    ],
    postprocessor: fis.plugin('autoprefixer')
});


// 添加css和image加载支持
fis.match('*.{js,jsx,ts,tsx,es}', {
    preprocessor: [
      fis.plugin('js-require-css'),
      fis.plugin('js-require-file', {
        useEmbedWhenSizeLessThan: 10 * 1024 // 小于10k用base64
      })
    ]
})

fis.match('/client/static/**.js', {
  parser: null,
  isMod: false
});

// 用 loader 来自动引入资源。
fis.match('::package', {
    postpackager: fis.plugin('loader')
});

// 禁用components
fis.unhook('components')
fis.hook('node_modules')

fis.match('/client/index.jsx', {
  isMod: false
})

配置项说明

  • mergeLevel 默认 1 npm 包去重。
    • 0 如果版本完全一致则去重。
    • 1 patch 版本号一致则去重。相当于 1.1.x
    • 2 min 版本号一致则去重。相当于 1.x
    • 3 忽略版本,只要包名一致则去重。
  • ignoreDevDependencies 默认为 false 标记是否忽略 devDependencies。
  • shimBuffer 默认为 true 自动检测 js 内容,存在 buffer 的调用,自动添加 buffer 的 shim 模块。(有些插件并不适用)
  • env 默认在代码压缩的情况下为 production 否则为 development。 支持配置或者回调函数。

FAQs

Package last updated on 16 May 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc