diff --git a/docs/guide/comparisons.md b/docs/guide/comparisons.md index 1e849f88a71a68..e582a8d389d0fb 100644 --- a/docs/guide/comparisons.md +++ b/docs/guide/comparisons.md @@ -1,38 +1,4 @@ -# Comparisons with Other No-Bundler Solutions - -## Snowpack - -[Snowpack](https://www.snowpack.dev/) is also a no-bundle native ESM dev server that is very similar in scope to Vite. Aside from different implementation details, the two projects share a lot in terms of technical advantages over traditional tooling. Vite's dependency pre-bundling is also inspired by Snowpack v1 (now [`esinstall`](https://github.com/snowpackjs/snowpack/tree/main/esinstall)). Some of the main differences between the two projects are: - -**Production Build** - -Snowpack's default build output is unbundled: it transforms each file into separate built modules, which can then be fed into different "optimizers" that perform the actual bundling. The benefit of this is that you can choose between different end-bundlers to fit specific needs (e.g. webpack, Rollup, or even esbuild), the downside is that it's a bit of a fragmented experience - for example, the esbuild optimizer is still unstable, the Rollup optimizer is not officially maintained, and different optimizers have different output and configurations. - -Vite opts to have a deeper integration with one single bundler (Rollup) in order to provide a more streamlined experience. It also allows Vite to support a [Universal Plugin API](./api-plugin) that works for both dev and build. - -Due to a more integrated build process, Vite supports a wide range of features that are currently not available in Snowpack build optimizers: - -- [Multi-Page Support](./build#multi-page-app) -- [Library Mode](./build#library-mode) -- [Automatic CSS code-splitting](./features#css-code-splitting) -- [Optimized async chunk loading](./features#async-chunk-loading-optimization) -- Official [legacy mode plugin](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) that generates dual modern/legacy bundles and auto delivers the right bundle based on browser support. - -**Faster Dependency Pre-Bundling** - -Vite uses [esbuild](https://esbuild.github.io/) instead of Rollup for dependency pre-bundling. This results in significant performance improvements in terms of cold server start and re-bundling on dependency invalidations. - -**Monorepo Support** - -Vite is designed to handle monorepo setups and we have users successfully using it with Yarn, Yarn 2, and PNPM based monorepos. - -**CSS Pre-Processor Support** - -Vite provides more refined support for Sass and Less, including improved `@import` resolution (aliases and npm dependencies) and [automatic `url()` rebasing for inlined files](./features#import-inlining-and-rebasing). - -**First Class Vue Support** - -Vite was initially created to serve as the future foundation of [Vue.js](https://vuejs.org/) tooling. Although as of 2.0 Vite is now fully framework-agnostic, the official Vue plugin still provides first-class support for Vue's Single File Component format, covering all advanced features such as template asset reference resolving, ` diff --git a/playground/css/main.js b/playground/css/main.js index 90f74c96793c55..c9384b6a79013c 100644 --- a/playground/css/main.js +++ b/playground/css/main.js @@ -47,6 +47,11 @@ text('.charset-css', charset) import './dep.css' import './glob-dep.css' +import { barModuleClasses } from 'css-js-dep' +document + .querySelector('.css-js-dep-module') + .classList.add(barModuleClasses.cssJsDepModule) + function text(el, text) { document.querySelector(el).textContent = text } @@ -92,3 +97,10 @@ text('.imported-css-globEager', JSON.stringify(globEager, null, 2)) import postcssSourceInput from './postcss-source-input.css?query=foo' text('.postcss-source-input', postcssSourceInput) + +import aliasContent from '#alias' +text('.aliased-content', aliasContent) +import aliasModule from '#alias-module' +document + .querySelector('.aliased-module') + .classList.add(aliasModule.aliasedModule) diff --git a/playground/css/package.json b/playground/css/package.json index 03c4964f0284ea..11dc33c48f7aa2 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -13,6 +13,7 @@ }, "devDependencies": { "css-dep": "link:./css-dep", + "css-js-dep": "file:./css-js-dep", "fast-glob": "^3.2.11", "less": "^4.1.3", "postcss-nested": "^5.0.6", diff --git a/playground/css/vite.config.js b/playground/css/vite.config.js index 639a1302debb88..c501213b47cded 100644 --- a/playground/css/vite.config.js +++ b/playground/css/vite.config.js @@ -10,7 +10,9 @@ module.exports = { resolve: { alias: { '@': __dirname, - spacefolder: __dirname + '/folder with space' + spacefolder: __dirname + '/folder with space', + '#alias': __dirname + '/aliased/foo.css', + '#alias-module': __dirname + '/aliased/bar.module.css' } }, css: { diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index 70f7ec252280a9..a7297511ea4649 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -81,11 +81,15 @@ const relativeRawResult = { } test('should work', async () => { - expect(await page.textContent('.result')).toBe( - JSON.stringify(allResult, null, 2) + await untilUpdated( + () => page.textContent('.result'), + JSON.stringify(allResult, null, 2), + true ) - expect(await page.textContent('.result-node_modules')).toBe( - JSON.stringify(nodeModulesResult, null, 2) + await untilUpdated( + () => page.textContent('.result-node_modules'), + JSON.stringify(nodeModulesResult, null, 2), + true ) }) diff --git a/playground/ssr-vue/vite.config.noexternal.js b/playground/ssr-vue/vite.config.noexternal.js index ce9a389defc68b..48a740c16cb1bf 100644 --- a/playground/ssr-vue/vite.config.noexternal.js +++ b/playground/ssr-vue/vite.config.noexternal.js @@ -1,8 +1,8 @@ -const config = require('./vite.config.js') +import config from './vite.config.js' /** * @type {import('vite').UserConfig} */ -module.exports = Object.assign(config, { +export default Object.assign(config, { ssr: { noExternal: /./ }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67f75f4da8630d..790ac42ccd2b7e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -377,6 +377,7 @@ importers: playground/css: specifiers: css-dep: link:./css-dep + css-js-dep: file:./css-js-dep fast-glob: ^3.2.11 less: ^4.1.3 postcss-nested: ^5.0.6 @@ -384,6 +385,7 @@ importers: stylus: ^0.58.1 devDependencies: css-dep: link:css-dep + css-js-dep: file:playground/css/css-js-dep fast-glob: 3.2.11 less: 4.1.3 postcss-nested: 5.0.6 @@ -411,6 +413,9 @@ importers: playground/css/css-dep: specifiers: {} + playground/css/css-js-dep: + specifiers: {} + playground/css/pkg-dep: specifiers: {} @@ -708,6 +713,9 @@ importers: playground/optimize-deps/nested-include: specifiers: {} + playground/optimize-deps/non-optimizable-include: + specifiers: {} + playground/optimize-missing-deps: specifiers: express: ^4.18.1 @@ -8709,6 +8717,12 @@ packages: version: 0.0.0 dev: false + file:playground/css/css-js-dep: + resolution: {directory: playground/css/css-js-dep, type: directory} + name: css-js-dep + version: 1.0.0 + dev: true + file:playground/define/commonjs-dep: resolution: {directory: playground/define/commonjs-dep, type: directory} name: commonjs-dep @@ -8877,7 +8891,7 @@ packages: file:playground/ssr-deps/no-external-css: resolution: {directory: playground/ssr-deps/no-external-css, type: directory} - name: primitive-export-css + name: no-external-css version: 0.0.0 dev: false