Giter Site home page Giter Site logo

complicated2018 / babel-plugin-import-fix Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lin-xi/babel-plugin-import-fix

0.0 0.0 0.0 37 KB

alter import module to certain module file path for smaller bundle and better performance

JavaScript 99.46% Makefile 0.54%

babel-plugin-import-fix's Introduction

babel-plugin-import-fix

Build Status Coverage Status npm package NPM downloads

alter import module to certain module file path for smaller bundle file and better performance

主要功能是修改import,缩小import的范围,减少bundle文件大小,提升性能


import {Button} from 'antd';

after fix:

import {Button} from 'antd/lib/button';
import 'antd/lib/button/style'

these fixies are made on ast. bundle file size decrease from 1.5Mb to 286Kb.


how to use

npm install babel-plugin-import-fix -D

config it in your .babelrc

在.babelrc里进行配置

.babelrc

{
  "presets": [
    ["es2015", { "modules": false }], "react"
  ],
  "plugins": ["import-fix"]
}

supported framework

framework status
xcui
antd
elementUI
material-ui
d3

more library will be supported increasingly

默认直接支持这些库,不需要配置,会不断增加支持的类型

extend usage:

you can overwrite the config or add new config like this:

扩展支持的库,如果没有css,可以不写cssPath,或设置为空

.babelrc

{
  "presets": [
    ["es2015", { "modules": false }], "react"
  ],
  "plugins": [["import-fix", [
    {
      'libraryName': 'xcui',
      'libraryPath': 'xcui/lib/${name}.js',
      'namePolicy': 'dash',
      'cssPath': ['xcui/lib/css/common.css', 'xcui/lib/css/${name}.css']
    },
    {
      'libraryName': 'antd',
      'libraryPath': 'antd/lib/${name}/index.js',
      'namePolicy': 'dash',
      'cssPath': 'antd/lib/${name}/style/index.css'
    }
  ]]]
}

cssPath can be a string or an array or an empty string, if you hava multiple css files to import, use an array. you may igonre cssPath if you don't need.

cssPath可以是字符或数组


name policy

three policy are supported

namePolicy选项

  • dash, date-picker
  • camel, DatePicker
  • underline, date_picker

default config:

默认配置

[
  {
    'libraryName': 'antd',
    'libraryPath': 'antd/lib/${name}/index.js',
    'namePolicy': 'dash',
    'cssPath': 'antd/lib/${name}/style/index.css'
  },
  {
    'libraryName': 'material-ui',
    'libraryPath': 'material-ui/${name}/index.js',
    'namePolicy': 'camel',
    'cssPath': ''
  },
  {
    'libraryName': 'xcui',
    'libraryPath': 'xcui/lib/${name}.js',
    'namePolicy': 'dash',
    'cssPath': ['xcui/lib/css/common.css', 'xcui/lib/css/${name}.css']
  },
  {
    'libraryName': 'element-ui',
    'libraryPath': 'element-ui/lib/${name}.js',
    'namePolicy': 'dash',
    'cssPath': ['element-ui/lib/theme-default/base.css', 'element-ui/lib/theme-default/${name}.css']
  },
  {
    'libraryName': 'd3',
    'libraryPath': 'd3-${name}/index.js',
    'namePolicy': 'dash',
    'cssPath': ''
  }
]

thanks:

https://github.com/ant-design/babel-plugin-import

babel-plugin-import-fix's People

Contributors

lin-xi avatar

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.