下js静态构建css、js路径问题

问题描述 投票:0回答:1

next js 静态构建和下载 本地打开html

错误图片

在下一个js静态构建之后,css js路径以'file:///'开头

我想更改路径

-- next.config.js
/** @type {import('next').NextConfig} */
const path = require('path');
const nextConfig = {
  output: 'export',
  reactStrictMode: false,
  images: {
    loader: "custom",
    loaderFile: "localImageLoader.js"
  },
  webpack(config, options) {
    config.resolve.modules.push(path.resolve("./"));

    return config;
  },
}

module.exports = nextConfig

我也尝试过 assetprfix: "./" 或 basepath: "./",但出现错误,因为它们不是以 / 开头。

next.js
1个回答
0
投票

试试这个

const nextConfig = {
  output: 'export',
  reactStrictMode: false,
  images: {
    loader: 'custom',
    loaderFile: 'localImageLoader.js',
  },
  assetPrefix: '', // Set to '' for relative paths, or a specific URL base if needed
  basePath: '', // No base path
  webpack(config, options) {
    config.resolve.modules.push(path.resolve('./'));

    return config;
  },
};

module.exports = nextConfig;

参考链接

© www.soinside.com 2019 - 2024. All rights reserved.