Comparing version 1.0.0-beta.10 to 1.0.0-beta.11
@@ -9,3 +9,3 @@ import { Ora } from 'ora'; | ||
} | ||
export declare const onRollupWarning: (spinner: Ora | undefined) => InputOptions['onwarn']; | ||
export declare function onRollupWarning(spinner: Ora | undefined, options: BuildConfig['optimizeDeps']): InputOptions['onwarn']; | ||
/** | ||
@@ -12,0 +12,0 @@ * Creates non-application specific plugins that are shared between the main |
@@ -34,24 +34,56 @@ "use strict"; | ||
]; | ||
exports.onRollupWarning = (spinner) => (warning, warn) => { | ||
if (warning.code === 'UNRESOLVED_IMPORT') { | ||
console.error(chalk_1.default.red(`[vite]: Rollup failed to resolve a module, this is most likely unintended because it can break your application at runtime. | ||
If you do want to externalize this module explicitly add it to \`rollupInputOptions.external\``)); | ||
throw new Error(warning.message); | ||
} | ||
if (warning.plugin === 'rollup-plugin-dynamic-import-variables' && | ||
dynamicImportWarningIgnoreList.some((msg) => warning.message.includes(msg))) { | ||
return; | ||
} | ||
if (!warningIgnoreList.includes(warning.code)) { | ||
// ora would swallow the console.warn if we let it keep running | ||
// https://github.com/sindresorhus/ora/issues/90 | ||
if (spinner) { | ||
spinner.stop(); | ||
const isBuiltin = require('isbuiltin'); | ||
function onRollupWarning(spinner, options) { | ||
return (warning, warn) => { | ||
if (warning.code === 'UNRESOLVED_IMPORT') { | ||
let message; | ||
const id = warning.source; | ||
const importer = warning.importer; | ||
if (isBuiltin(id)) { | ||
let importingDep; | ||
if (importer) { | ||
const pkg = JSON.parse(utils_1.lookupFile(importer, ['package.json']) || `{}`); | ||
if (pkg.name) { | ||
importingDep = pkg.name; | ||
} | ||
} | ||
const allowList = options && options.allowNodeBuiltins; | ||
if (importingDep && allowList && allowList.includes(importingDep)) { | ||
return; | ||
} | ||
const dep = importingDep | ||
? `Dependency ${chalk_1.default.yellow(importingDep)}` | ||
: `A dependency`; | ||
message = | ||
`${dep} is attempting to import Node built-in module ${chalk_1.default.yellow(id)}.\n` + | ||
`This will not work in a browser environment.\n` + | ||
`Imported by: ${chalk_1.default.gray(importer)}`; | ||
} | ||
else { | ||
message = | ||
`[vite]: Rollup failed to resolve import "${warning.source}" from "${warning.importer}".\n` + | ||
`This is most likely unintended because it can break your application at runtime.\n` + | ||
`If you do want to externalize this module explicitly add it to\n` + | ||
`\`rollupInputOptions.external\``; | ||
} | ||
throw new Error(message); | ||
} | ||
warn(warning); | ||
if (spinner) { | ||
spinner.start(); | ||
if (warning.plugin === 'rollup-plugin-dynamic-import-variables' && | ||
dynamicImportWarningIgnoreList.some((msg) => warning.message.includes(msg))) { | ||
return; | ||
} | ||
} | ||
}; | ||
if (!warningIgnoreList.includes(warning.code)) { | ||
// ora would swallow the console.warn if we let it keep running | ||
// https://github.com/sindresorhus/ora/issues/90 | ||
if (spinner) { | ||
spinner.stop(); | ||
} | ||
warn(warning); | ||
if (spinner) { | ||
spinner.start(); | ||
} | ||
} | ||
}; | ||
} | ||
exports.onRollupWarning = onRollupWarning; | ||
/** | ||
@@ -173,3 +205,3 @@ * Creates non-application specific plugins that are shared between the main | ||
treeshake: { moduleSideEffects: 'no-external' }, | ||
onwarn: exports.onRollupWarning(spinner), | ||
onwarn: onRollupWarning(spinner, options.optimizeDeps), | ||
...rollupInputOptions, | ||
@@ -176,0 +208,0 @@ plugins: [ |
@@ -15,3 +15,2 @@ "use strict"; | ||
const pluginAssets_1 = require("./pluginAssets"); | ||
const pluginBuiltInBail_1 = require("./pluginBuiltInBail"); | ||
const debug = require('debug')('vite:optimize'); | ||
@@ -128,6 +127,5 @@ const KNOWN_IGNORE_LIST = new Set([ | ||
// treeshake: { moduleSideEffects: 'no-external' }, | ||
onwarn: build_1.onRollupWarning(spinner), | ||
onwarn: build_1.onRollupWarning(spinner, options), | ||
...config.rollupInputOptions, | ||
plugins: [ | ||
pluginBuiltInBail_1.createBuiltInBailPlugin(config.optimizeDeps && config.optimizeDeps.allowNodeBuiltins), | ||
pluginAssets_1.depAssetExternalPlugin, | ||
@@ -134,0 +132,0 @@ ...(await build_1.createBaseRollupPlugins(root, resolver, config)), |
{ | ||
"name": "vite", | ||
"version": "1.0.0-beta.10", | ||
"version": "1.0.0-beta.11", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Evan You", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
341158
99
6009