Code Monkey home page Code Monkey logo

nuxt-webpack-optimisations's Introduction

NPM Downloads

Webpack Build Time Optimisations for Nuxt.js! ⚡️
Instantly speed up your Nuxt.js webpack build time.


Status: Stable v2 ✅ , bridge ✅, v3 ⚠️
Made possible by my Sponsor Program 💖
Follow me @harlan_zw 🐦

Previously: "nuxt-build-optimisations", see migration notes.

Can't use Vite with Nuxt yet?

i.e Nuxt Vite or Nuxt 3

Truly sad... But I do have some good news. While you won't be able to achieve instant app starts anytime soon, nuxt-webpack-optimisations can get things snappy again.

Webpack Optimisations

nuxt-webpack-optimisations is a collection of webpack config changes that will let you speed up your build times and audit them.

By making smarter and riskier assumptions on how you want to run your environment in development, this module has been benchmarked to reduce your build time by ~50% when cold ☃ , ~95%+ when hot 🔥 (using hardsource).

How risky are we talking

The riskier optimisations are enabled only on development and relate to over caching, which is always easy to fix with a good old rm -rf node_modules/.cache 💩.

✔️ This module has been tested to cause no issues in production environments.

Features

Features are enabled by their risk profile. The risk profile is the likelihood of issues coming up.

Tools

Always

Dev

Production

Compatibility

  • ✔️ Nuxt v2
  • ✔️ Nuxt bridge
  • ⚠ Nuxt v3 Note: Vite needs to be disabled. You probably don't need this module.

Setup

Install the module.

yarn add -D nuxt-webpack-optimisations
# npm i -D nuxt-webpack-optimisations

Within your nuxt.config.ts or nuxt.config.js

buildModules: [
  'nuxt-webpack-optimisations',
],

Typescript

For Nuxt config typescript support, add the module within your tsconfig.json.

{
  "compilerOptions": {
    "types": [
      "nuxt-webpack-optimisations"
    ]
  }
}

Usage

All non-risky features are enabled by default, only hardsource and parallel are disabled.

If you'd like to get more performance than the default you can try

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    features: {
      // enable risky optimisations in dev only
      hardSourcePlugin: process.env.NODE_ENV === 'development',
      parallelPlugin: process.env.NODE_ENV === 'development',
    }
  }
}

Note: It's recommended to avoid running risky in non-development environments. Caching in CI environments can lead to issues.

Modifying Esbuild Behaviour

Out of the box the esbuild optimisations will use the default options, only changing the target for earlier browsers to support legacy code.

In most cases you won't need to change this, if you do then you'll need to configure the client, server and modern (if using) build separately.

Example:

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    // https://github.com/privatenumber/esbuild-loader#%EF%B8%8F-options
    esbuildLoaderOptions: {
      client: {
        // any esbuild options can be set here
        minifyIdentifiers: false,
        // as well as any esbuild-loader options
        target: 'es2015',
      },
      server: {
        minifyIdentifiers: false,
        target: 'node14',
      },
      // only needed if you're using modern: true
      modern: {
        target: 'es2017',
      },
    }
  }
}

Something isn't working

A lot of the speed improvements are from heavy caching, if you have any issues the first thing you should do is clear your cache.

# Linux / Mac
rm -rf node_modules/.cache

# windows
rd /s  "node_modules/.cache"

If you'd like to see what features are running you can enable the debug mode.

// nuxt.config.ts
export default {
  webpackOptimisations: {
    debug: true
  }
}

Configuration

Features

Type: object

Default: Non-risky features enabled.

You can disable features if you'd like to skip optimisations.

// nuxt.config.ts
export default {
  webpackOptimisations: {
    features: {
      // Note: just an example of keys, these are all keys and their default
      postcssNoPolyfills: true,
      esbuildLoader: true,
      esbuildMinifier: true,
      imageFileLoader: true,
      webpackOptimisations: true,
      cacheLoader: true,
      hardSourcePlugin: false,
      parallelPlugin: false,
    }
  }
}

esbuildLoaderOptions

Type: object

Default:

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    // https://github.com/privatenumber/esbuild-loader#%EF%B8%8F-options
    esbuildLoaderOptions: {
      client: {
        target: 'es2015',
      },
      server: {
        target: 'node14',
      },
      modern: {
        target: 'es2015',
      },
    }
  }
}

See esbuild-loader for full options.

esbuildMinifyOptions

Type: object

Default:

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    // https://github.com/privatenumber/esbuild-loader#minifyplugin
    esbuildMinifyOptions: {
      client: {
        target: 'es2015',
      },
      server: {
        target: 'node14',
      },
      modern: {
        target: 'es2015',
      },
    }
  },
}

See esbuild-loader for full options.

Measure

Type: boolean or object

Default: false

When measure is enabled with true (options or environment variable), it will use the speed-measure-webpack-plugin.

If the measure option is an object it is assumed to be speed-measure-webpack-plugin options.

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    measure: {
      outputFormat: 'humanVerbose',
      granularLoaderData: true,
      loaderTopFiles: 10
    }
  }
}

You can use an environment variable to enable the measure as well.

package.json

{
  "scripts": {
    "measure": "export NUXT_MEASURE=true; nuxt dev"
  }
}

Note: Some features are disabled with measure on, such as caching.

Measure Mode

Type: client | server | modern | all

Default: client

Configure which build will be measured. Note that non-client builds may be buggy and mess with HMR.

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    measureMode: 'all'
  }
}

Gotchas

Vue Property Decorator / Vue Class Component

Your babel-loader will be replaced with esbuild, which doesn't support class decorators in js.

You can either migrate your scripts to typescript or disabled the esbuild loader.

Disable Loader

// nuxt.config.ts
export default {
  // ...
  webpackOptimisations: {
    features: {
      esbuildLoader: false
    }
  }
}

Migrate to TypeScript

tsconfig.json

{
  "experimentalDecorators": true
}
<script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'

@Component
export default class HelloWorld extends Vue {
  data () {
    return {
      hello: 'test'
    }
  }
}
</script>

Credits

Sponsors

License

MIT License © 2022 Harlan Wilton

nuxt-webpack-optimisations's People

Contributors

appinteractive avatar harlan-zw avatar kn0wn avatar mannil avatar mathe42 avatar n1j0 avatar sugoidesune avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nuxt-webpack-optimisations's Issues

bug during startup in devmode

Describe the bug
ERROR config.module.rules[ruleKey].use.filter is not a function 15:46:34

at node_modules/nuxt-build-optimisations/dist/index.js:2160:54
at Array.forEach ()
at Array.esbuildOptimiser (node_modules/nuxt-build-optimisations/dist/index.js:2156:25)
at WebpackBundler. (node_modules/nuxt-build-optimisations/dist/index.js:2248:28)
at next (node_modules/@nuxt/utils/dist/utils.js:1879:27)
at WebpackBundler. (node_modules/@nuxt/utils/dist/utils.js:1894:12)
at WebpackBundler. (node_modules/@nuxt/utils/dist/utils.js:1888:29)
at WebpackClientConfig.extendConfig (node_modules/@nuxt/webpack/dist/webpack.js:4879:37)
at WebpackClientConfig.config (node_modules/@nuxt/webpack/dist/webpack.js:4914:45)
at WebpackClientConfig.config (node_modules/@nuxt/webpack/dist/webpack.js:5078:26)
at WebpackBundler.getWebpackConfig (node_modules/@nuxt/webpack/dist/webpack.js:5386:19)
at WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:5393:12)
at Builder.build (node_modules/@nuxt/builder/dist/builder.js:5634:30)
at async Object._buildDev (node_modules/@nuxt/cli/dist/cli-dev.js:106:5)
at async Object.startDev (node_modules/@nuxt/cli/dist/cli-dev.js:64:7)
at async Object.run (node_modules/@nuxt/cli/dist/cli-dev.js:51:5)

Risky profile doesnt seems to work

Describe the bug
Risky profile doesn't seem to work as it should, the others seems to work perfectly.
If I enable hardsource and parallel directly into my nuxt config, my build time on the 2nd run is 8 sec, with this library it takes always 52sec, the same as safe and experimental.

No Optimizations
dev: 1m30s ~ 40s
hot reload: 1.6 ~ 2.3s

Safe
dev: 51 ~ 54s
hot reload: 1.8s ~ 2.2

Experimental
dev: 51 ~ 52
hot reload: 1.8 ~ 1.9

Risky
dev: 52 ~ 53
hot reload: 2.2 ~ 2.3

Expected behavior
I was expecting it to do the hardsource and parallel, but it doesn't...

I am using vue 2, with nuxt 2.15.7, and vuetify 2.5.8.

Missing CSS after second npm run dev

There is no CSS applied when rerunning npm run dev after the initial caching has finished
I have set up everything as described, using nuxt 2.15.8, added what was needed in buildModules to enable optimisation, didn't change the default settings. After the first npm run dev, when the cache is initialized everything worked properly. Stopped dev server, started the dev server again using npm run dev, it went pretty fast, and after it finished there was no CSS used on the website. If I disabled the cacheLoader, there were images, but the startup speed was back to its original slow speed.

To Reproduce
Steps to reproduce the behavior:

  1. npm install nuxt-webpack-optimisations
  2. Add 'nuxt-webpack-optimisations' to nuxt.config.js buildModules
  3. npm run dev
  4. Everything is fine after it fnishes
  5. Stop dev server
  6. npm run dev
  7. After the dev server starts, CSS disappears, is not applied anymore.

There should be CSS after caching also
It should load CSS even after caching is initialized and dev server restarted.

Screenshots - This is how main CSS is loaded in the layout files
image

can't find This dependency `.nuxt/client.js `

Describe the bug

ERROR Failed to compile with 1 errors friendly-errors 23:29:38

This dependency was not found: friendly-errors 23:29:38
friendly-errors 23:29:38

  • /Users/terry/neoncms/.nuxt/client.js in multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
    friendly-errors 23:29:38
    To install it, you can run: npm install --save /Users/terry/neoncms/.nuxt/client.js friendly-errors 23:29:38

✖ Client
Compiled with some errors in 706.15ms

✖ Server
Compiled with some errors in 333.29ms

To Reproduce
package:

"nuxt": "^2.15.3",
"nuxt-i18n": "^6.22.1",
"nuxt-seo": "^1.5.0",
"@nuxtjs/auth": "^4.9.1",
"@nuxtjs/axios": "^5.13.1",
"@w3cub/nuxt-express-module": "^0.0.24",
 "nuxt-build-optimisations": "^1.0.2",
 "nuxt-svg-loader": "^1.2.0",

config

export default {
  // mode: 'universal',
  srcDir: 'client/',

  server: {
    // port: 3100, // default: 3000
    host: '0.0.0.0' // default: localhost
  },
  alias: {
    'assets': resolve(__dirname, './client/assets'),
    '~themes': resolve(__dirname, './client/themes')
  },
 buildModules: [
    'nuxt-build-optimisations',
    // 'nuxt-vite',
    // '~modules/svg.js',
    ['@nuxtjs/eslint-module', { fix: true }]
  ],
  buildOptimisations: {
    // profile: process.env.NODE_ENV === 'development' ? 'risky' : 'experimental'
    profile: false
  },

  /*
  ** Nuxt.js modules
  */
  modules: [
    ['nuxt-i18n'],
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    '@nuxtjs/auth',
    ['@w3cub/nuxt-express-module', { expressPath: '../server/', setupPath: '../server/app.js' }], //, routesPath: 'server/routes',
    // "@nuxtjs/svg"
    // '@nuxtjs/pwa',

  ],
}

Screenshots
image

esbuild-loader error

For some reason this worked just fine last week and now this week is throwing the following error regardless of profile. Project compiles fine if I disable.

✔ Client: Compiled with some errors in 21.10s
ERROR Failed to compile with 1 errors
ERROR in ./.nuxt/client.js
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
spawn Unknown system error -8
at PoolWorker.fromErrorObj (/usr/src/app/node_modules/thread-loader/dist/WorkerPool.js:346:12)
at /usr/src/app/node_modules/thread-loader/dist/WorkerPool.js:219:29
at mapSeries (/usr/src/app/node_modules/neo-async/async.js:3625:14)
at PoolWorker.onWorkerMessage (/usr/src/app/node_modules/thread-loader/dist/WorkerPool.js:173:34)
at /usr/src/app/node_modules/thread-loader/dist/WorkerPool.js:146:14
at Socket.onChunk (/usr/src/app/node_modules/thread-loader/dist/readBuffer.js:40:9)
at Socket.emit (events.js:400:28)
at ChildProcess.spawn (internal/child_process.js:403:11)
at spawn (child_process.js:667:9)
at Object.spawnWithSignal [as spawn] (child_process.js:871:17)
at ensureServiceIsRunning (/usr/src/app/node_modules/esbuild/lib/main.js:1716:29)
at transform (/usr/src/app/node_modules/esbuild/lib/main.js:1631:37)
at Object.ESBuildLoader (/usr/src/app/node_modules/esbuild-loader/dist/loader.js:58:37)
@ multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
✔ Server: Compiled with some errors in 21.06s

Incompatible with nuxt 2.16.0 due to nuxt upgrading to postcss8 and nuxt3 style postcss8 options

Describe the bug

Running nuxt 2.16 with the nuxt-webpack-optimisations feature postcssNoPolyfills enabled leads to the following blocking error:

ValidationError: Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade a working nuxt 2 w/ nuxt-webpack-optimisations project to use nuxt 2.16.0
  2. Run nuxt run dev
  3. See error

Reason for the error

Nuxt 2.16.0 upgraded to postcss 8, and changed the postcss options format to the 'postcssOptions' style. See this PR for details, but essentially the change looks like this:

<2.16.0

postcss: {
    plugins: {
      "postcss-import": {},
      "tailwindcss/nesting": {},
      tailwindcss: {},
      autoprefixer: {},
    },
},

2.16.0

postcss: {
    postcssOptions: {
      plugins: {
        "postcss-import": {},
        "tailwindcss/nesting": {},
        tailwindcss: {},
        autoprefixer: {},
      },
    },
},

This causes an error as when the postcssNoPolyfills feature is enabled nuxt-webpack-optimisations modifies postcss.options (instead of postcss.postcssOptions), unless nuxt is 3+.

Workaround
A temporary workaround is to disable the postcssNoPolyfills feature, ex:

webpackOptimisations: {
    debug: true,
    features: {
      // disabled because nuxt-webpack-optimizations does not support postcss8 postcssOptions style config in nuxt2
      postcssNoPolyfills: false,
    },
}

Suggested Fix
Modify src/augmentation/useDisableDevPostcssPresetEnv.ts:16 to use getNuxtVersion instead of isNuxt3 and check for version >= 2.16 or >=3.

Experimental And Safe don't change anything

Describe the bug

I have BootstrapVue on my project, but I am trying to remove it, the gain after removing is ~ 15 second

Without your module :

  • The build takes :
✔ Client
  Compiled successfully in 1.05m
✔ Server
  Compiled successfully in 39.31s
✨  Done in 107.14s.
  • The dev takes :
✔ Client
  Compiled successfully in 1.12m
✔ Server
  Compiled successfully in 1.12m

That's why I need your module ❤️

With your module : (safe / experimental)

  • The build takes :
✔ Client
  Compiled successfully in 1.01m
✔ Server
  Compiled successfully in 35.60s
✨  Done in 101.43s.
  • The dev takes :
✔ Client
  Compiled successfully in 1.05m
✔ Server
  Compiled successfully in 1.02m

With your module : (risky)

  • The build takes :
✔ Client
  Compiled successfully in 1.01m
✔ Server
  Compiled successfully in 35.60s
✨  Done in 101.43s.
  • The dev takes :
 WARN  [hardsource:5dc8067d] Node dependencies changed. Building new cache.
✔ Client
  Compiled successfully in 1.06m
✔ Server
  Compiled successfully in 26.67s
 WARN  [hardsource:fc136279] Node dependencies changed. Building new cache.

=> Second time (thanks to the cache)

✔ Client
  Compiled successfully in 9.90s
✔ Server
  Compiled successfully in 1.96s
  • I'm still 1 minute away on Experimental and Safe mode

To Reproduce
My nuxt.config.js

import { sitemapRoutes } from './sitemapRoutes'
const isDeveloppement = !['production', 'staging'].includes(
  process.env.ENVIRONMENT
)

if (process.env.NODE_ENV !== 'production') require('dotenv').config()

module.exports = {
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.SITE_NAME,
    titleTemplate: `%s | ${process.env.SITE_NAME}`,
    meta: [
      { charset: 'utf-8' },
      { content: 'IE=edge,chrome=1', 'http-equiv': 'X-UA-Compatible' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'Meta description' }
    ],
    link: [
      { rel: 'shortcut icon', type: 'image/x-icon', href: '/favicon.png' },
      {
        rel: 'apple-touch-icon',
        type: 'image/x-icon',
        href: '/touch_icon.png'
      },
      {
        rel: 'stylesheet',
        href: process.env.ICOMOON_CDN
      }
    ],
    script: [
      {
        src:
          '//cdn.mouseflow.com/projects/****.js',
        defer: true
      },
      {
        src: 'https://js.stripe.com/v3/',
        defer: true
      }
    ]
  },

  // Auto import components
  components: true,

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },

  /*
  ** Global CSS
  */
  css: ['@/assets/styles/app.sass'],

  /*
  ** Environment variables
  */
  env: {
    action_cable_websocket_url: process.env.ACTION_CABLE_WEBSOCKET_URL,
    algolia_id: process.env.ALGOLIA_ID,
    algolia_index_prefix: process.env.ALGOLIA_INDEX_PREFIX,
    algolia_search_key: process.env.ALGOLIA_SEARCH_KEY,
    api_host: process.env.API_HOST,
    api_port: process.env.API_PORT,
    api_prefix: process.env.API_PREFIX,
    app_domain: process.env.APP_DOMAIN,
    base_url: process.env.BASE_URL,
    browser_language: process.env.BROWSER_LANGUAGE,
    collection_ids: process.env.COLLECTION_IDS,
    collectionist_phone_be: process.env.COLLECTIONIST_PHONE_BE,
    collectionist_phone_ch: process.env.COLLECTIONIST_PHONE_CH,
    collectionist_phone_fr: process.env.COLLECTIONIST_PHONE_FR,
    collectionist_phone_gb: process.env.COLLECTIONIST_PHONE_GB,
    environment: process.env.ENVIRONMENT,
    http_password: process.env.HTTP_PASSWORD,
    http_username: process.env.HTTP_USERNAME,
    img_cdn_domain: process.env.IMG_CDN_DOMAIN,
    node_env: process.env.NODE_ENV,
    segment_token: process.env.SEGMENT_TOKEN,
    signatureui_en: process.env.SIGNATUREUI_EN,
    signatureui_fr: process.env.SIGNATUREUI_FR,
    site_name: process.env.SITE_NAME,
    stripe_public_key: process.env.STRIPE_PUBLIC_KEY,
    twitter: process.env.TWITTER,
    yousign_api_key: process.env.YOUSIGN_API_KEY
  },

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    { src: '~plugins/api.js' },
    { src: '~plugins/breakpointChecker.js' },
    { src: '~plugins/browserLanguage' },
    { src: '~plugins/getWishlistToken.js' },
    { src: '~plugins/veeValidate.js' },
    { src: '~plugins/vueScrollto' },
    { src: '~plugins/vueTouchEvents.js' },
    { src: '~plugins/stripe.server.js' },
    { src: '~plugins/actioncableVue.client.js' },
    { src: '~plugins/analytics.client.js' },
    { src: '~plugins/aos.client.js' },
    { src: '~plugins/carousel.client.js' },
    { src: '~plugins/lazysizes.client.js' },
    { src: '~plugins/tracking.client.js' },
    { src: '~plugins/vueCookieLaw.client.js' }
  ],

  serverMiddleware: isDeveloppement
    ? []
    : ['~/serverMiddleware/rateLimiter', '~/serverMiddleware/redirect'],

  /*
  ** Nuxt.js build modules
  */
  buildModules: [
    '@nuxtjs/tailwindcss',
    '@nuxtjs/device',
    'nuxt-build-optimisations'
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    '@nuxtjs/dayjs',
    'nuxt-basic-auth-module', // authentication on staging
    // Doc: https://auth.nuxtjs.org/
    '@nuxtjs/auth', // user account authentication
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios',
    // Doc: https://bootstrap-vue.js.org/docs/
    'bootstrap-vue/nuxt',
    // Doc: https://nuxt-community.github.io/nuxt-i18n/
    [
      'nuxt-i18n',
      {
        baseUrl: process.env.BASE_URL,
        locales: [
          { code: 'fr', iso: 'fr-FR', name: 'fr', file: 'fr.js' },
          { code: 'en', iso: 'en-US', name: 'en', file: 'en.js' }
        ],
        strategy: 'prefix',
        defaultLocale: 'fr',
        rootRedirect: 'fr',
        seo: false,
        lazy: true,
        langDir: 'lang/',
        detectBrowserLanguage: false
      }
    ],
    'cookie-universal-nuxt',
    [
      '~/modules/bugsnag',
      {
        browserApiKey: process.env.BUGSNAG_CLIENT_API_KEY,
        serverApiKey: process.env.BUGSNAG_SERVER_API_KEY,
        bugsnagOptions: {
          enabledReleaseStages: ['production', 'staging'],
          releaseStage: process.env.APP_DOMAIN
        }
      }
    ],
    '@nuxtjs/sitemap'
  ],
  sitemap: {
    hostname: `${process.env.BASE_URL}`,
    gzip: true,
    cacheTime: 1,
    defaults: {
      changefreq: 'monthly',
      lastmod: new Date()
    },
    exclude: process.env.SITEMAP_EXCLUDE_URL.split(','),
    routes: async () => sitemapRoutes()
  },
  dayjs: {
    locales: ['en', 'fr'],
    defaultLocale: 'fr',
    plugins: ['isBetween']
  },
  bootstrapVue: {
    icons: false,
    bvCSS: false,
    css: false,
    components: ['BCol'],
    componentPlugins: ['BVToastPlugin']
  },
  basic: {
    name: process.env.HTTP_USERNAME,
    pass: process.env.HTTP_PASSWORD,
    enabled: process.env.ENVIRONMENT === 'staging'
  },
  /*
  ** Auth module configuration
  */
  auth: {
    plugins: ['~/plugins/auth.js'],
    redirect: {
      // in plugins/auth.js, we use i18n with 'name' provided here:
      login: 'login',
      logout: 'login',
      callback: 'login',
      home: 'myaccount-profile'
    },
    watchLoggedIn: false,
    cookie: {
      prefix: ''
    }
  },
  /*
  ** Axios module configuration
  */
  axios: {
    // See https://github.com/nuxt-community/axios-module#options
    proxy: false,
    https: true
  },
  /*
  ** Progress bar
  */
  loading: {
    color: '#dbbc8f',
    failedColor: '#dbbc8f',
    height: '4px'
  },
  tailwindcss: {
    cssPath: '~/assets/styles/tailwind.sass'
  },
  /*
  ** Build configuration
  */

  build: {
    transpile: ['vee-validate/dist/rules'],
    publicPath:
      process.env.NODE_ENV === 'production' ? process.env.CDN_URL : '/_nuxt/',
    // For Bootstrap
    babel: {
      compact: true
    },
    extend(config, ctx) {
      // Run ESLint on save
      if (ctx.isDev && ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }
  }
}

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Dev start error "Invalid host defined options"

Just updated from nuxt-build-optimisation to nuxt-webpack-optimisations, followed the migration guide, uninstalled the old one, installed the new version, remove node_modules/.cache, copy the suggested config to nuxt.config.js but it does not run.

My package.json dep list

"dependencies": {
"@nuxtjs/apollo": "^4.0.1-rc.5",
"@nuxtjs/axios": "^5.13.1",
"@nuxtjs/strapi": "^0.3.1",
"cookieparser": "^0.1.0",
"cross-env": "^5.2.0",
"graphql-tag": "^2.12.4",
"js-cookie": "^2.2.1",
"nuxt": "^2.15.4",
"nuxt-i18n": "^6.27.0",
"nuxt-webpack-optimisations": "^2.0.3",
"quagga": "^0.12.1"
},
"devDependencies": {
"@nuxtjs/eslint-config": "^3.1.0",
"@nuxtjs/eslint-module": "^2.0.0",
"@nuxtjs/pwa": "^3.3.5",
"@nuxtjs/vuetify": "^1.11.3",
"babel-eslint": "^10.1.0",
"eslint": "^7.25.0",
"eslint-plugin-nuxt": "^1.0.0"
}

And when i run "npm run dev" this error appears.
FATAL Invalid host defined options 10:00:07

at ModuleContainer.module.exports (node_modules\nuxt-webpack-optimisations\module.cjs:3:3)
at ModuleContainer.addModule (node_modules@nuxt\core\dist\core.js:239:34)
at node_modules@nuxt\utils\dist\utils.js:639:43
at async ModuleContainer.ready (node_modules@nuxt\core\dist\core.js:51:7)
at async Nuxt._init (node_modules@nuxt\core\dist\core.js:478:5)

[email protected] - Server compiled with some errors

Describe the bug
Running nuxt 2.17 with the nuxt-webpack-optimizations esbuildLoader feature enabled leads to the following non-blocking error:

✖ Server
  Compiled with some errors in 1.05s

Reason for the error
No errors are reported in the output. However, the application works.
I tried to track down the source of the error but couldn't find anything.
Workaround
When the esbuildLoader option is disabled, compilation finishes without errors.

Screenshots
image

Additional context
I was already using nuxt-webpack-optimizations in 2.16.3 and had no problems. I upgraded today to 2.17.

Minification is not applied by default

Describe the bug
When building for production, the generated files aren't minified.

To Reproduce
Steps to reproduce the behavior:

  1. Install this module and add it to buildModules
  2. Build for production
  3. Do a Lighthouse pass on the site and it'll tell you that JS isn't minified

Expected behavior
JS to be minified by default in build mode.

Screenshots
image

Client fails to compile

Can't see the .nuxt/client.js file when compiling, but if I disable the plugin it works fine.


 ERROR  Failed to compile with 1 errors                                                            friendly-errors 15:42:05

This dependency was not found:                                                                     friendly-errors 15:42:05
                                                                                                   friendly-errors 15:42:05
* /Users/daniel/code/directlink-portal/.nuxt/client.js in multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
                                                                                                   friendly-errors 15:42:05
To install it, you can run: npm install --save /Users/daniel/code/directlink-portal/.nuxt/client.js

✖ Client
  Compiled with some errors in 516.94ms

✖ Server
  Compiled with some errors in 512.00ms

Nuxt Build Optimisations 1.0.6 with experimental profile
Nuxt 2.15.8

CleanShot 2021-08-31 at 15 43 05

nuxtCtx.set is not a function

Describe the bug
After a clean installation of this module i get following error when starting up:
nuxtCtx.set is not a function

To Reproduce
Steps to reproduce the behavior:
follow instruction in the readme

Expected behavior
dev server start works
Screenshots
Bildschirmfoto 2022-01-13 um 10 09 42

ESBuildMinifierPlugin failed to import

Describe the bug
When compile in the productive environment it throws an error in Node 16 saying that the ESBuildMinifierPlugin can not be found in the named exports because is a CommonJS Module (i'm not sure if it present in others versions).

To Reproduce
Steps to reproduce the behavior:

  1. Start a fresh Nuxt2 app
  2. Install and active the nuxt-webpack-optimisations module
  3. Try to compile with the "build" command in Node 16

Expected behavior
It should not thrown error

Error description from Nuxt2
SyntaxError: Named export 'ESBuildMinifyPlugin' not found. The requested module 'esbuild-loader' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'esbuild-loader';
const { ESBuildMinifyPlugin } = pkg;

Possible workaround / solution
Import first the esbuild-loader and destructuring the MinifyPlugin, just as the error says.

Change to

import esbuild from 'esbuild-loader';

const { ESBuildMinifyPlugin } = esbuild;

Additional context
I think the new native support of ES Modules in Node 16 can affect.

bug: fails on dev due to svg-loader

Describe the bug
Dev server doesn't work

To Reproduce
Steps to reproduce the behavior:

  1. Clone repository https://github.com/debs-obrien/debbie.codes
  2. install module and run dev
  3. Module build failed (from ./node_modules/vue-svg-loader/index.js):

Expected behavior
Generate works but dev doesn't

Screenshots
Screenshot 2021-02-11 at 13 10 15

Additional context
Don't see any improvements in speed, removed node modules and yarn lock. Generation takes same time and dev takes same time but then breaks

Fails with vue-property-decorator and vue-class-component

Describe the bug
I'm getting this errors in experimental mode:

Module build failed (from ./node_modules/esbuild-loader/dist/index.js):                       friendly-errors 11:22:51
Error: Transform failed with 1 error:
...\components\page\View.vue:29:0: error: Unexpected "@"

To Reproduce
I guess this is to do with use of Decorators in vue-property-decorator and vue-class-component. I have "experimentalDecorators": true,

can't use measure option

Describe the bug
When I set the measure option to true. It will throw "nuxt.hook is not a function" error.
nuxt version: 2.14.4
nuxt-build-optimisations version: 1.5.0

To Reproduce
Steps to reproduce the behavior:

  1. install nuxt-build-optimisations
  2. set buildModules: ['nuxt-build-optimisations']
  3. set buildOptimisations: { profile: 'safe', measure: true }

Expected behavior
Show SMP result and build successfully.

Screenshots
image

Additional context
If I remove measure option, it works fine.

Profile: 'false' is still applying optimizations

Describe the bug
When module is installed and buildOptimisations profile is 'false', I still get 2x to 3x faster build times.
When module is uninstalled, build times go back to regular.

To Reproduce
Steps to reproduce the behavior:

  1. Install module and configure buildOptimisations.profile as 'false'
  2. Run nuxt build and store the measures for client and server
  3. Uninstall module (and remove settings from nuxt.config.js).
  4. Run nuxt build and store the measures for client and server

Expected behavior
When module is installed and buildOptimisations profile is 'false', it should not perform any optimization.

Avoid overriding users default nuxt configurations

There are certain options within the nuxt config that the user may have specifically opted out of. Such as parralel or hardsource, in this case we should honour their configuration instead of changing it.

This may require parsing the nuxt.config.js again

Throws error if /middleware doesn't exist

Describe the bug

Throws a friendly error if the middleware directory doesn't exist.

ERROR  Failed to compile with 1 errors                                       

This relative module was not found:                                           
                                                                             
* ./middleware in ./.nuxt/auth.js    

To Reproduce

  • Open a Nuxt project without middleware folder
  • Start dev server

Expected behavior

Should work also without middleware dir, if you don't have any middleware there is no need for the directory. Nuxt itself also allows it.

Screenshots

Screen Shot 2021-02-11 at 19 32 43

Documentation is ambiguous / unclear on certain aspects

Hi,

I'm a bit at loss concerning the module configuration. Maybe you can you provide a more exhaustive example config to demonstrate various options and how to use them exactly.

I'm not intimately familiar with esbuild, so I can only take guesses on how to specify more granular options. Specifically, I would like to disable esbuild's minifyIdentifiers and I have no clue how to do this after reading the docs.

If you could shed some light on the topic, It'd be greatly appreciated.

Features

There are two different examples for configuration:

webpackOptimisations: {
  // hard source is the riskiest, if you have issues don't enable it
  hardSourcePlugin: process.env.NODE_ENV === 'development',
  parallelPlugin: process.env.NODE_ENV === 'development',
}

and also

webpackOptimisations: {
  features: {
    // Note: just an example of keys, these are all keys and their default
    hardSourcePlugin: false,
    parallelPlugin: false,
  }
}

So are features configured top-level or nested under features?

Esbuild config

On configuring esbuildMinifyOptions, the documentation just says

export default {
  client: {
    target: 'es2015',
  },
  server: {
    target: 'node14',
  },
  modern: {
    target: 'es2015',
  },
}

export default like what? From where? client, server? Huh?! Wouldn't this go into webpackOptimisations in nuxt.config.js, like so:

webpackOptimisations: {
  esbuildMinifyOptions: {
    // ...
  }
}

Thanks!

Error on startup: SyntaxError: Invalid or unexpected token

Describe the bug
When i installed plugin and start app, i get an error

To Reproduce
Steps to reproduce the behavior:

  1. install via yarn.
  2. Add to nuxt.config.js installation below
  3. try to npm run dev

Expected behavior
To build and work

Screenshots
image

Additional context
Nuxt version 2.14.11. No bridge to v3.
Firstly got an error on node@14, therefore i updated to node@18, but this does't help
Installation:

buildModules: [
    'nuxt-webpack-optimisations'
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.