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

fix: avoid using prefixIdenntifier in esm #519

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module.exports = {
preset: 'ts-jest',
globals: {
__USE_BUILD__: process.argv.indexOf('-use-build') >= 0
__USE_BUILD__: process.argv.indexOf('-use-build') >= 0,
__BROWSER__: true
},
testEnvironment: 'jsdom',
transform: {
"^.+\\.vue$": "vue-jest",
"^.+\\js$": "babel-jest"
'^.+\\.vue$': 'vue-jest',
'^.+\\js$': 'babel-jest'
},
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'],
setupFiles: ['./setup.js']
Expand Down
21 changes: 11 additions & 10 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@ const banner = `
`

function createEntry(options) {
const {
format,
input,
isBrowser
} = options
const { format, input, isBrowser } = options

const isEsmBrowser = format === 'es' && isBrowser

const config = {
input,
external: [
'vue',
isEsmBrowser ? '@vue/compiler-dom/dist/compiler-dom.esm-browser' : '@vue/compiler-dom',
isEsmBrowser
? '@vue/compiler-dom/dist/compiler-dom.esm-browser'
: '@vue/compiler-dom'
],
plugins: [
replace({
values: {
"process.env.NODE_ENV": "true"
'process.env.NODE_ENV': 'true',
__BROWSER__: isEsmBrowser
},
preventAssignment: true
}),
resolve(), commonjs(), json()
resolve(),
commonjs(),
json()
],
output: {
banner,
Expand All @@ -45,7 +46,7 @@ function createEntry(options) {
format,
globals: {
vue: 'Vue',
'@vue/compiler-dom': 'VueCompilerDOM',
'@vue/compiler-dom': 'VueCompilerDOM'
}
}
}
Expand Down Expand Up @@ -82,5 +83,5 @@ export default [
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: false }),
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: true }),
createEntry({ format: 'iife', input: 'src/index.ts', isBrowser: true }),
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false }),
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false })
]
7 changes: 5 additions & 2 deletions src/utils/compileSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export function processSlot(source = '', Vue = vue) {
`<SlotWrapper v-bind="$attrs">${template}</SlotWrapper>`,
{
mode: 'function',
prefixIdentifiers: true
prefixIdentifiers: __BROWSER__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may need to update tsconfig (or somewhere else?) to make this compile.

}
)
const createRenderFunction = new Function('Vue', `'use strict';\n${code}`)
const createRenderFunction = new Function(
'Vue',
__BROWSER__ ? `'use strict';\n${code}` : code
)

return {
inheritAttrs: false,
Expand Down
8 changes: 5 additions & 3 deletions test-dts/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
// it's intended. We cannot use directives like @ts-ignore or @ts-nocheck since
// that would suppress the errors that should be caught.

import '../types/global'

export function describe(_name: string, _fn: () => void): void

export function expectType<T>(value: T): void
export function expectError<T>(value: T): void
export function expectAssignable<T, T2 extends T = T>(value: T2): void

export type IsUnion<T, U extends T = T> = (T extends any
? (U extends T ? false : true)
: never) extends false
export type IsUnion<T, U extends T = T> = (
T extends any ? (U extends T ? false : true) : never
) extends false
? false
: true
1 change: 1 addition & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var __BROWSER__: boolean