Skip to content

Commit

Permalink
fix: cjs bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Aug 31, 2023
1 parent 35375c3 commit b1ccb7b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 49 deletions.
2 changes: 1 addition & 1 deletion playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import Unplugin from '../src/vite'
import Unplugin from '../dist/vite'

export default defineConfig({
plugins: [
Expand Down
6 changes: 2 additions & 4 deletions playground/vue.config.mjs → playground/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Unplugin from '../dist/webpack.js'

export default {
module.exports = {
configureWebpack: {
plugins: [
Unplugin({
require('../dist/webpack.cjs')({
info: [
async () => {
await new Promise(resolve => setTimeout(resolve, 1000))
Expand Down
19 changes: 3 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/print.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as korlorist from 'kolorist'
import boxen from 'boxen'
import type { MessageValue, Options } from '../types'

function log(msg: string | void) {
Expand All @@ -8,7 +9,6 @@ function log(msg: string | void) {
}

async function printWithBoxen(res: MessageValue) {
const { default: boxen } = await import('boxen')
res.borderStyle = res.borderStyle || 'none'
// @ts-expect-error missing type
log(boxen(res.text, res))
Expand Down
14 changes: 14 additions & 0 deletions src/core/unplugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { UnpluginFactory } from 'unplugin'
import { createUnplugin } from 'unplugin'
import type { Options } from '../types'
import { vite, webpack } from '.'

export const unpluginFactory: UnpluginFactory<Options> = options => ({
name: 'unplugin-printer',
vite: vite(options),
webpack: webpack(options),
})

export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)

export default unplugin
16 changes: 2 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
import type { UnpluginFactory } from 'unplugin'
import { createUnplugin } from 'unplugin'
import type { Options } from './types'
import { vite, webpack } from './core'

export const unpluginFactory: UnpluginFactory<Options> = options => ({
name: 'unplugin-printer',
vite: vite(options),
webpack: webpack(options),
})

export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)

export default unplugin
export * from './types'
export { default } from './core/unplugin'
8 changes: 2 additions & 6 deletions src/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import type { Options } from './types'
import '@nuxt/schema'
import { print } from './core/print'

export interface ModuleOptions extends Options {

}

export default defineNuxtModule<ModuleOptions>({
export default defineNuxtModule<Options>({
meta: {
name: 'nuxt-unplugin-printer',
configKey: 'unpluginPrinter',
},
setup(options, nuxt) {
setup(options: Options, nuxt) {
nuxt.hook('vite:serverCreated', (_, { isServer }) => {
if (isServer)
print(options.info)
Expand Down
7 changes: 4 additions & 3 deletions src/vite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createVitePlugin } from 'unplugin'
import { unpluginFactory } from '.'
import type { Plugin } from 'vite'
import type { Options } from './types'
import unplugin from '.'

export default createVitePlugin(unpluginFactory)
export default unplugin.vite as (options?: Options | undefined) => Plugin
5 changes: 2 additions & 3 deletions src/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createWebpackPlugin } from 'unplugin'
import { unpluginFactory } from '.'
import unplugin from '.'

export default createWebpackPlugin(unpluginFactory)
export default unplugin.webpack
5 changes: 4 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { Options } from 'tsup'

export default <Options>{
entryPoints: [
entry: [
'src/*.ts',
],
clean: true,
format: ['cjs', 'esm'],
dts: true,
splitting: true,
onSuccess: 'npm run build:fix',
shims: false,
noExternal: ['boxen'],
external: ['korlorist'],
}

0 comments on commit b1ccb7b

Please sign in to comment.