简体   繁体   English

Next.js 自定义配置导致索引 404 - 下一个图像,下一个 css,webpack,lquip-loader

[英]Next.js custom config resulting in 404 on index - next-images, next-css, webpack, lquip-loader

I'm attempting to get next-images and next-css to work alongside editing my webpack config (via next-css) to allow for a image-loader to parse the images..我正在尝试让 next-images 和 next-css 与编辑我的 webpack 配置(通过 next-css)一起工作,以允许图像加载器解析图像..

After attempting this I found next-compose-plugins which is meant to help in loading of next plugins..尝试此操作后,我发现了 next-compose-plugins 旨在帮助加载下一个插件..

After following their documentation I've somewhat pieced together a next.config.js:在遵循他们的文档之后,我拼凑了一个 next.config.js:


const withPlugins = require('next-compose-plugins');
const withCSS = require('@zeit/next-css')
const withImages = require('next-images');

// next.js configuration
const nextConfig = {
  useFileSystemPublicRoutes: false,
  distDir: 'build',
};

module.exports = withPlugins([
  [withCSS, {
    webpack: (config, options) => {
      const { isServer, dev } = options
      config.module.rules.push({
            test: /\.(jpe?g|png|svg|gif|ico|webp)$/,
            use: [
              {
                loader: 'lqip-loader',
                options: {
                  fallback: 'file-loader',
                  base64: !dev,
                  publicPath: '/_next/static/images/',
                  outputPath: `${isServer ? '../' : ''}static/images/`,
                  name: '[name]-[hash].[ext]',
                  palette: true
                }
              }
            ]
          })
        return config
      },
      cssLoaderOptions: {
        url: false
       }
    }
  ],
  withImages
], nextConfig)


I'm not sure if this is correct however, as since doing so, and restarting my local dev server, I'm now 404-ing on http://localhost:3000/ 但是我不确定这是否正确,因为这样做并重新启动本地开发服务器后,我现在在 http://localhost:3000/ 上运行 404

Any help greatly appreciated as I've hit a wall in that the console log is simply a 404 and I'm unable to debug..任何帮助都非常感谢,因为我碰壁了,因为控制台日志只是一个 404,我无法调试..

Thanks in advance,提前致谢,

James詹姆士

const nextConfig = {
  useFileSystemPublicRoutes: true,
  distDir: 'build',
};

Setting this to true, resolved my 404将此设置为 true,解决了我的 404

I cross referenced this alongside a defult next.js config and it's default it true so no idea why the next-compose-plugins doc's suggest this but yeah.. hopefully that helps someone further down the line..我在一个默认的 next.js 配置旁边交叉引用了这个,它默认是真的,所以不知道为什么 next-compose-plugins 文档会建议这个但是是的.. 希望这可以帮助某人进一步下线..

ofc shoutout @Ramakay for the correct answer ofc 喊出@Ramakay 以获得正确答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM