Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

refactor(schema,webpack)!: split out webpack and postcss build options #2812

Merged
merged 31 commits into from
Feb 25, 2022

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jan 19, 2022

πŸ”— Linked issue

resolves nuxt/nuxt#12853

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR refactors the webpack bundler implementation out of a class, splits out vite, webpack & postcss options as top-level config items, and changes how you set the builder (build.builder can be vite, webpack, or a custom object with a bundle() method).

It also now shares postcss plugin configuration between webpack & vite, meaning that cssnano is added to the vite preset.

πŸ‘‰ Migration steps

Update builder option

If you are using webpack, you will need to update your nuxt.config:

  import { defineNuxtConfig } from 'nuxt3'

  export default defineNuxtConfig({
-   vite: false,
+   builder: 'webpack'
  })

You will also now need to install the webpack builder separately. Add this to package.json:

{
  "devDependencies": {
    "@nuxt/webpack-builder": "npm:@nuxt/webpack-builder-edge@latest"
  }
}

Update postcss plugins

If you have configured your postcss plugins separately, you will now need to do so through a new top-level config option. This will apply to both webpack & vite builders.

  import { defineNuxtConfig } from 'nuxt3'

  export default defineNuxtConfig({
-   build: {
-     postcss: {
-       postcssOptions: {
-         plugins: {
-           'postcss-import': {}
-         }
-       }
-     }
-   },
+   postcss: {
+     plugins: {
+       'postcss-import': {}
+     }
+   }
  })

πŸ“ TODO

  • I have linked an issue or discussion.
  • Remove babel code/dependencies from webpack implementation (or re-enable)
  • Finish refactor (can be made cleaner)
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Jan 19, 2022

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: 710942f

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/6218ff5c635dcd000749a227

@danielroe danielroe changed the title refactor(schema): split out webpack and postcss build options refactor(kit,schema,webpack): split out webpack and postcss build options Jan 19, 2022
@danielroe danielroe changed the title refactor(kit,schema,webpack): split out webpack and postcss build options refactor(schema,webpack)Β±: split out webpack and postcss build options Jan 19, 2022
@danielroe danielroe changed the title refactor(schema,webpack)Β±: split out webpack and postcss build options refactor(schema,webpack)!: split out webpack and postcss build options Jan 19, 2022
@danielroe danielroe self-assigned this Jan 19, 2022
@pi0 pi0 self-assigned this Jan 19, 2022
@danielroe danielroe added the 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing label Jan 20, 2022
@danielroe danielroe marked this pull request as ready for review January 21, 2022 15:20
@atinux
Copy link
Member

atinux commented Feb 11, 2022

We may want to list it into https://github.com/nuxt/framework/discussions/2883 as well

const useVite = nuxt.options.vite !== false
const { bundle } = await (useVite ? import('@nuxt/vite-builder') : import('@nuxt/webpack-builder'))
const { bundle } = typeof nuxt.options.builder === 'string'
? await tryImportModule(nuxt.options.builder, { paths: nuxt.options.rootDir })
Copy link
Member

@pi0 pi0 Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this works :D (resolution of tryImportModule is CJS)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x chore enhancement New feature or request kit 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing schema vite webpack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor build options (split out webpack-only options)
3 participants