@lenochen/dio
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

DIO

基于ts编写的工具库,同步至npm

我是DIO哒

Usage

storage

storage 简化了 localStorage 的 getItem 和 setItem 方法, 自动转化存取格式

import { storage } from '@lenochen/dio'
const boo = { a: 1, b: 2}
storage.setItem('bar', boo)
storage.getItem('bar') // { a: 1, b: 2 } 

踩坑

output.libraryTarget

此坑在编写工具库项目DIO时遇到,该项目基于webpack打包。但是在使用模块方式引入包文件时却无法获取到打包的内容。

// @lenochen/dio
// index.js 工具库项目DIO打包入口
const a = require('./a.js')
module.exports = { a }

// Usage 使用DIO的另一个项目
// npm i @lenochen/dio
import { a } from '@lenochen/dio'
console.log(a) // undefined

经调查发现问题出在DIO项目webpack配置的output的参数上

// @lenochen/dio
// webpack.config.js
{
  ...,
  output: {
    filename: 'index.bundle.js',
    path: 'dist',
    // ++++
    libraryTarget: 'commonjs2' // 增加此参数后,打包文件便可以使用模块化方式引入
    // ++++
  },
  ...
}

详细libraryTarget配置解析见 output.libraryTarget

Readme

Keywords

Package Sidebar

Install

npm i @lenochen/dio

Weekly Downloads

2

Version

1.0.3

License

ISC

Unpacked Size

97.5 kB

Total Files

15

Last publish

Collaborators

  • lenochen