Skip to content

Commit

Permalink
feat: show version info
Browse files Browse the repository at this point in the history
Gives users knowledge the module is running if they're debugging performance.
  • Loading branch information
harlan-zw committed May 27, 2022
1 parent 619689b commit 8161f15
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
39 changes: 23 additions & 16 deletions packages/nuxt-webpack-optimisations/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,55 @@ export default defineNuxtModule<NuxtWebpackOptimisationOptions>({
},
// support @nuxt/kit legacy
defaults: defaultOptions,
async setup(webpackOptimisationOptions: NuxtWebpackOptimisationOptions, nuxt) {
async setup(options: NuxtWebpackOptimisationOptions, nuxt) {
const logger = consola.withScope(NAME)

if (webpackOptimisationOptions.debug) {
if (options.debug) {
// Debug = 4
logger.level = 4
}

// handle v1 config
if (webpackOptimisationOptions.profile) {
logger.warn(`${NAME} the "profile" config has been deprecated. Use "risky" instead.`)
if (webpackOptimisationOptions.profile === 'risky') {
webpackOptimisationOptions.features!.hardSourcePlugin = true
webpackOptimisationOptions.features!.parallelPlugin = true
if (options.profile) {
logger.warn(`${NAME} the "profile" config has been deprecated. Use \`"risky: true"\` or \`"risky: false"\` instead.`)
if (options.profile === 'risky') {
options.features!.hardSourcePlugin = true
options.features!.parallelPlugin = true
}
else if (webpackOptimisationOptions.profile === 'safe') {
webpackOptimisationOptions.features!.postcssNoPolyfills = false
else if (options.profile === 'safe') {
options.features!.postcssNoPolyfills = false
}
}

// avoid being too verbose
if (options.displayVersionInfo && nuxt.options.dev) {
nuxt.hook('build:before', () => {
logger.info(`\`nuxt-webpack-optimisations v${version}\` running risky optimisations: \`${options.risky}\`.`)
})
}

// @ts-expect-error handle deprecated config
if (webpackOptimisationOptions.esbuildLoaderOptions?.target) {
if (options.esbuildLoaderOptions?.target) {
// @ts-expect-error handle deprecated config
const target = webpackOptimisationOptions.esbuildLoaderOptions.target
webpackOptimisationOptions.esbuildLoaderOptions = {
const target = options.esbuildLoaderOptions.target
options.esbuildLoaderOptions = {
client: { target },
server: { target },
modern: { target },
}
}
// @ts-expect-error handle deprecated config
if (webpackOptimisationOptions.esbuildMinifyOptions?.target) {
if (options.esbuildMinifyOptions?.target) {
// @ts-expect-error handle deprecated config
const target = webpackOptimisationOptions.esbuildMinifyOptions.target
webpackOptimisationOptions.esbuildMinifyOptions = {
const target = options.esbuildMinifyOptions.target
options.esbuildMinifyOptions = {
client: { target },
server: { target },
modern: { target },
}
}

const options = webpackOptimisationOptions as ResolvedOptions
const options = options as ResolvedOptions

// hacky identification of the nuxt-vite module for Nuxt 2
if (isNuxt2(nuxt) && nuxt.options.buildModules.includes('nuxt-vite')) {
Expand Down
15 changes: 15 additions & 0 deletions packages/nuxt-webpack-optimisations/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface ResolvedOptions {
* Enable logger debug to be displayed/
*/
debug: boolean
/**
* Run risky augmentations.
*/
risky?: false
/**
* Which webpack config to use with SpeedMeasurePlugin.
*/
Expand All @@ -42,6 +46,11 @@ export interface ResolvedOptions {
* Which features to run.
*/
features: Record<Feature, Boolean>
/**
* Shows nuxt-webpack-optimisations version info on build:before hook.
* @default true
*/
displayVersionInfo?: boolean
}

export interface NuxtWebpackOptimisationOptions {
Expand Down Expand Up @@ -78,6 +87,12 @@ export interface NuxtWebpackOptimisationOptions {
* Which features to run.
*/
features?: PartialRecord<Feature, Boolean>

/**
* Shows nuxt-webpack-optimisations version info on build:before hook.
* @default true
*/
displayVersionInfo?: boolean
}

export interface AugmentationArgs {
Expand Down

0 comments on commit 8161f15

Please sign in to comment.