Skip to content

Commit 1cb537b

Browse files
authored
fix(next-plugin): url statements in vanilla css would not respect next's setup for resolving assets (#1155)
1 parent 40d7e72 commit 1cb537b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.changeset/calm-starfishes-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/next-plugin': patch
3+
---
4+
5+
Fix URL statements not not respecting Next's setup for resolving assets

packages/next-plugin/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
22
import browserslist from 'browserslist';
33
import { lazyPostCSS } from 'next/dist/build/webpack/config/blocks/css';
44
import { findPagesDir } from 'next/dist/lib/find-pages-dir';
5+
import { cssFileResolve } from 'next/dist/build/webpack/config/blocks/css/loaders/file-resolve';
56
import NextMiniCssExtractPluginDefault from 'next/dist/build/webpack/plugins/mini-css-extract-plugin';
67

78
import type webpack from 'webpack';
@@ -60,6 +61,18 @@ const getVanillaExtractCssLoaders = (
6061
postcss,
6162
importLoaders: 1,
6263
modules: false,
64+
url: (url: string, resourcePath: string) =>
65+
cssFileResolve(
66+
url,
67+
resourcePath,
68+
options.config.experimental?.urlImports,
69+
),
70+
import: (url: string, _: any, resourcePath: string) =>
71+
cssFileResolve(
72+
url,
73+
resourcePath,
74+
options.config.experimental?.urlImports,
75+
),
6376
},
6477
});
6578

0 commit comments

Comments
 (0)