最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

next.js - Configuring "raw-loader" with turbopack - Stack Overflow

programmeradmin0浏览0评论

My project is running in Next.JS 15.0.3 with turbopack.

raw-loader is now supported with turbopack and so I'd like to configure it to load webgl shaders files. I've installed raw-loader as dev dependency.

My next.config.ts looks like so:

import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
    sassOptions: {
        silenceDeprecations: ['legacy-js-api'],
    },
    experimental: {
        turbo: {
            useSwcCss: true,
            rules: {
                '*p.svg': {
                    loaders: ['@svgr/webpack'],
                    as: 'component',
                },
                '/.(glsl|vs|fs|vert|frag)$/': {
                    loaders: ['raw-loader'],
                },
            },
        },
    },
};

export default nextConfig;

I also tried to add webpack with no result:

cont nextConfig: NextConfig = {
  ...,
    webpack(config) {
        config.module.rules.push({
            test: /\.(glsl|vs|fs|vert|frag)$/,
            exclude: /node_modules/,
            use: ['raw-loader'],
        });
        return config;
    },
}

I always get this error:

Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it.

My project is running in Next.JS 15.0.3 with turbopack.

raw-loader is now supported with turbopack and so I'd like to configure it to load webgl shaders files. I've installed raw-loader as dev dependency.

My next.config.ts looks like so:

import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
    sassOptions: {
        silenceDeprecations: ['legacy-js-api'],
    },
    experimental: {
        turbo: {
            useSwcCss: true,
            rules: {
                '*p.svg': {
                    loaders: ['@svgr/webpack'],
                    as: 'component',
                },
                '/.(glsl|vs|fs|vert|frag)$/': {
                    loaders: ['raw-loader'],
                },
            },
        },
    },
};

export default nextConfig;

I also tried to add webpack with no result:

cont nextConfig: NextConfig = {
  ...,
    webpack(config) {
        config.module.rules.push({
            test: /\.(glsl|vs|fs|vert|frag)$/,
            exclude: /node_modules/,
            use: ['raw-loader'],
        });
        return config;
    },
}

I always get this error:

Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it.
Share Improve this question edited Mar 11 at 12:10 heskir asked Mar 11 at 12:00 heskirheskir 156 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To fix this, I needed to write it this way:

    experimental: {
        turbo: {
            useSwcCss: true,
            rules: {
                ...,
                '*.{glsl,vs,fs,vert,frag}': {
                    loaders: ['raw-loader'],
                    as: '*.js',
                },
            },
        },
    },
发布评论

评论列表(0)

  1. 暂无评论