Code Monkey home page Code Monkey logo

fis3-hook-node_modules's Introduction

fis3-hook-node_modules

fis3 对npm的node_modules模块的支持

demo

NPM version

NPM

Install

npm install fis3-hook-node_modules -g

暂时process, buffer等node全局变量的兼容还需手动安装依赖模块(之后会升级fis3已实现自动安装) 请安装至你的项目目录下面

npm install process buffer is-buffer --save

安装插件的的时候务必要带上--save或者--save-dev, 否则会出现文件查找不到的问题

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')

Tips

fis.hook('commonjs') 一定要在 fis.hook('node_modules')之前, 否则会出现文件找不到的问题

Config

  • useDev 加载 devDependencies 的模块, 默认为false

如何像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
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.