@niocn/plugin-transform-import
v0.1.3
Published
For some libraries, such as lodash can achieve on-demand loaded by converting the import statement
Downloads
4
Maintainers
Readme
@niocn/plugin-transform-import
For some libraries such as LoDash, you can convert import statements to load on demand
Installation
$ npm install @niocn/plugin-transform-import -D
# or yarn
$ yarn add @niocn/plugin-transform-import -D
Getting started
const pluginTransformImport = require('@niocn/plugin-transform-import');
const babelCore = require('@babel/core');
const babelTypes = require('@babel/types');
const source = `
import { flatten as x, concat } from 'lodash'
`;
const result = babelCore.transform(source, {
plugins: [pluginTransformImport],
});
console.log(result.code);
test('test', () => {
expect(result.code).toMatch(/lodash\/x/);
expect(result.code).toMatch(/import concat from "lodash\/concat"/);
});