1.1.2 • Published 3 years ago

babel-plugin-tree-shaking-import v1.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

babel-plugin-tree-shaking-import

NPM version Build Status Coverage Status

Install

npm i babel-plugin-tree-shaking-import -D

or

yarn add babel-plugin-tree-shaking-import -D

Example

Converts

import { Button } from 'element-ui';

to

var button = require('element-ui/lib/button.js');
require('element-ui/packages/theme-chalk/src/button.scss');

Usage

Use with babel-loader

module.exports = {
  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: [
              [
                'tree-shaking-import',
                {
                  libraryName: 'element-ui',
                  libDir: 'lib',
                  styleLibraryDir: 'packages',
                  styleLibraryName: 'theme-chalk/src',
                  style: false,
                  ext: '.scss',
                },
              ],
            ],
          },
        },
      },
    ],
  },
};

Use with nuxt.config.js

module.exports = {
  babel: {
    plugins: [
      [
        'tree-shaking-import',
        {
          libraryName: 'element-ui',
          libDir: 'lib',
          styleLibraryDir: 'packages',
          styleLibraryName: 'theme-chalk/src',
          style: false,
          ext: '.scss',
        },
      ],
    ],
  },
};

More options see babel-plugin-component