-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
72 additions
and
70 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
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 |
---|---|---|
@@ -1,23 +1,46 @@ | ||
import type { Preset, Environment } from './types' | ||
import { resolveRuntime } from './utils' | ||
|
||
export function env (...presets: Preset[]) { | ||
const options: Environment = { | ||
export function env (...presets: Preset[]): Environment { | ||
const _env: Environment = { | ||
alias: {}, | ||
inject: {}, | ||
polyfill: [] | ||
polyfill: [], | ||
external: [] | ||
} | ||
|
||
for (const preset of presets) { | ||
// Alias | ||
if (preset.alias) { | ||
Object.assign(options.alias, preset.alias) | ||
for (const from in preset.alias) { | ||
_env.alias[from] = resolveRuntime(preset.alias[from]) | ||
} | ||
} | ||
|
||
// Inject | ||
if (preset.inject) { | ||
Object.assign(options.inject, preset.inject) | ||
for (const global in preset.inject) { | ||
if (Array.isArray(preset.inject[global])) { | ||
const [id, ...path] = preset.inject[global] | ||
_env.inject[global] = [resolveRuntime(id), ...path] | ||
} else { | ||
_env.inject[global] = resolveRuntime(preset.inject[global] as string) | ||
} | ||
} | ||
} | ||
|
||
// Polyfill | ||
if (preset.polyfill) { | ||
options.polyfill.push(...preset.polyfill) | ||
_env.polyfill.push( | ||
...(preset.polyfill.map(p => resolveRuntime(p)).filter(Boolean) as string[]) | ||
) | ||
} | ||
|
||
// External | ||
if (preset.external) { | ||
_env.external.push(...preset.external) | ||
} | ||
} | ||
|
||
return options | ||
return _env | ||
} |
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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
export { default as node } from './node' | ||
export { default as nodeless } from './nodeless' | ||
export { default as vue2 } from './vue2' | ||
export { default as vue3 } from './vue3' |
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import { r, NodeBuiltinModules, mockAll } from '../utils' | ||
import { NodeBuiltinModules, resolveAll } from '../utils' | ||
import type { Preset } from '../types' | ||
|
||
export default { | ||
alias: { | ||
...mockAll(NodeBuiltinModules), | ||
...resolveAll(NodeBuiltinModules, 'un/mock/proxy'), | ||
|
||
// Custom | ||
http: r('node/http'), | ||
process: r('polyfill/process'), | ||
_process: require.resolve('process/browser.js'), | ||
http: 'un/node/http', | ||
process: 'un/polyfill/process', | ||
_process: 'process/browser.js', | ||
|
||
// Browserify | ||
buffer: require.resolve('buffer/index.js'), | ||
util: require.resolve('util/util.js'), | ||
events: require.resolve('events/events.js'), | ||
inherits: require.resolve('inherits/inherits_browser.js'), | ||
buffer: 'buffer/index.js', | ||
util: 'util/util.js', | ||
events: 'events/events.js', | ||
inherits: 'inherits/inherits_browser.js', | ||
|
||
// npm | ||
etag: r('mock/noop'), | ||
'mime-db': r('npm/mime-db'), | ||
mime: r('npm/mime'), | ||
_mime: require.resolve('mime/lite.js') | ||
etag: 'un/mock/noop', | ||
'mime-db': 'un/npm/mime-db', | ||
mime: 'un/npm/mime', | ||
_mime: 'mime/lite.js' | ||
}, | ||
|
||
inject: { | ||
process: r('polyfill/process'), | ||
process: 'un/polyfill/process', | ||
Buffer: ['buffer', 'Buffer'] | ||
}, | ||
|
||
polyfill: [ | ||
r('polyfill/process') | ||
'un/polyfill/process' | ||
] | ||
} as Preset |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
"esModuleInterop": true, | ||
"strict": true, | ||
"declaration": true, | ||
"outDir": "lib", | ||
"types": [ | ||
"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