0

我正在开发一个 shopify 应用程序。我使用 shopify 文档开始了这个项目。Shopify CLI:https ://shopify.dev/apps/tools/cli/getting-started 问题是由于某种原因 webpack 未配置为处理 png 文件。我无法编译该项目。

错误信息:./pages/logo.png 1:0 Module parse failed: Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders (Source code omitted for this binary file)

在此处输入图像描述

我尝试添加文件加载器并将其添加到配置中,但应用程序崩溃了。任何人都可以在这里帮忙吗?

next.config.js:

const { parsed: localEnv } = require('dotenv').config();

const webpack = require('webpack');
const apiKey = JSON.stringify(process.env.SHOPIFY_API_KEY);

module.exports = {
  webpack: (config) => {
    const env = { API_KEY: apiKey };
    config.plugins.push(new webpack.DefinePlugin(env));

// Add ESM support for .mjs files in webpack 4
config.module.rules.push({
  test: /\.mjs$/,
  include: /node_modules/,
  type: 'javascript/auto',
});

//My file loader addition
config.module.rules.push({
  test: /\.(jpe?g|png|svg|gif|ico|eot|ttf|woff|woff2|mp4|pdf|webm|txt)$/,
  loader: 'file-loader',
  use:{ 'dist/[path][name].[ext]'}
});

return config;
  },
};
4

0 回答 0