Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with transform.ts #257

Closed
christophrathvaltech opened this issue Aug 3, 2023 · 0 comments
Closed

Issue with transform.ts #257

christophrathvaltech opened this issue Aug 3, 2023 · 0 comments

Comments

@christophrathvaltech
Copy link

christophrathvaltech commented Aug 3, 2023

I'm building a production build with vite-plugin-dts v3.4.0 and i get an error.

image

It seems, that in line 101 of
vite-plugin-dts/src/transform.ts

the argument aliases was set to undefined by vite config or other plugins and is not checked by the condition below.

...
function transformAliasImport(filePath, content, aliases, exclude = []) {
  if (!aliases.length)
    return content;
 ...

I've forked this repo and fixed this line by

  if (!aliases || !aliases.length)

and it works for my usecase.

Heres my vite.config.js

import multiInput from 'rollup-plugin-multi-input'
import {assetDir, entryFileNames, processAssetFileNames, processChunkFileNames} from './config/assets.js'
import dts from 'vite-plugin-dts'
import {resolve} from 'path'

/** @type {import('vite').UserConfig} */
export default {
    publicDir: 'static',
    assetsInclude: ['**/*.md', '**/*.svg'],
    build: {
        minify: true,
        assetsDir: assetDir,
        sourcemap: true,
        lib: {
            entry: './src/index.ts',
            formats: ['es'] // pure ESM package
        },
        rollupOptions: {
            output: {
                entryFileNames: entryFileNames,
                assetFileNames: processAssetFileNames,
                chunkFileNames: processChunkFileNames
            },
            external: [
                'lit',
                'lit-element',
                'lit-html',
                'lit/html.js',
                'lit/directives/class-map.js',
                'lit/directives/if-defined.js',
                'lit/directives/style-map.js',
                'lit/directives/unsafe-html.js',
                'lit/directives/unsafe-svg.js',
                'lit/directives/repeat.js',
                'lit/decorators.js',
                '@open-wc/testing-helpers',
                '@open-wc/testing'
            ],
            input: [
                'src/index.ts',
                'src/components/**/index.ts',
                'src/modules/**/index.ts',
                'src/utilities/**/index.ts',
                'src/internal/utils/**/index.ts',
                'src/mixins/index.ts'
            ],
            plugins: [
                multiInput(),
                dts({
                    outDir: 'dist',
                    include: ['src']
                })
            ]
        },
        commonjsOptions: {
            include: 'node_modules/**'
        },
        dynamicImportVarsOptions: {
            include: ['src/**/*.(js|ts|svg)']
        }
    },
    test: {
        globals: true,
        environment: 'jsdom',
        setupFiles: ['./config/vitest-setup.ts']
    }
}

@qmhc qmhc closed this as completed in fc51b68 Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant