-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundle): support autoExternal configuration (#74)
- Loading branch information
Showing
28 changed files
with
525 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@e2e/auto-external-default", | ||
"dependencies": { | ||
"react": "^18.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], | ||
source: { | ||
entry: { | ||
main: '../fixtures/src/index.ts', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@e2e/auto-external-with-sub-path", | ||
"dependencies": { | ||
"react": "^18.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], | ||
source: { | ||
entry: { | ||
main: './src/index.ts', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
import ReactJsx from 'react/jsx-runtime'; | ||
|
||
export const foo = () => { | ||
return [React.version, ReactJsx.jsx]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@e2e/auto-external-false", | ||
"dependencies": { | ||
"react": "^18.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
{ | ||
...generateBundleEsmConfig(__dirname), | ||
autoExternal: false, | ||
}, | ||
{ | ||
...generateBundleCjsConfig(__dirname), | ||
autoExternal: false, | ||
}, | ||
], | ||
source: { | ||
entry: { | ||
main: '../fixtures/src/index.ts', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react'; | ||
|
||
export const foo = () => { | ||
return React.version; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { join } from 'node:path'; | ||
import { buildAndGetResults } from '@e2e/helper'; | ||
import { expect, test } from 'vitest'; | ||
|
||
test('auto external default should works', async () => { | ||
const fixturePath = join(__dirname, 'default'); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(entries.esm).toContain( | ||
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"', | ||
); | ||
|
||
expect(entries.cjs).toContain( | ||
'var external_react_namespaceObject = require("react");', | ||
); | ||
}); | ||
|
||
test('auto external sub path should works', async () => { | ||
const fixturePath = join(__dirname, 'external-sub-path'); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(entries.esm).toContain( | ||
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"', | ||
); | ||
expect(entries.esm).toContain( | ||
'import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime"', | ||
); | ||
|
||
expect(entries.cjs).toContain( | ||
'var external_react_namespaceObject = require("react");', | ||
); | ||
expect(entries.cjs).toContain( | ||
'var jsx_runtime_namespaceObject = require("react/jsx-runtime");', | ||
); | ||
}); | ||
|
||
test('auto external false should works', async () => { | ||
const fixturePath = join(__dirname, 'false'); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(entries.esm).not.toContain( | ||
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"', | ||
); | ||
|
||
expect(entries.cjs).not.toContain( | ||
'var external_react_namespaceObject = require("react");', | ||
); | ||
}); | ||
|
||
test('externals should overrides auto external', async () => { | ||
const fixturePath = join(__dirname, 'with-externals'); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
|
||
expect(entries.esm).toContain( | ||
'import * as __WEBPACK_EXTERNAL_MODULE_react1__ from "react1"', | ||
); | ||
|
||
expect(entries.cjs).toContain( | ||
'var external_react1_namespaceObject = require("react1");', | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@e2e/auto-external-with-externals", | ||
"dependencies": { | ||
"react": "^18.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], | ||
output: { | ||
externals: { | ||
react: 'react1', | ||
}, | ||
}, | ||
source: { | ||
entry: { | ||
main: '../fixtures/src/index.ts', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,6 @@ export default defineConfig({ | |
}, | ||
}, | ||
output: { | ||
externals: { | ||
express: 'express', | ||
}, | ||
target: 'node', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
logger: { | ||
warn: () => {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './config'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type PkgJson = { | ||
dependencies?: Record<string, string>; | ||
peerDependencies?: Record<string, string>; | ||
devDependencies?: Record<string, string>; | ||
[key: string]: unknown; | ||
}; |
Oops, something went wrong.