next-remove-imports icon indicating copy to clipboard operation
next-remove-imports copied to clipboard

ECMAScript Usage with NextConfig

Open Pfed-prog opened this issue 1 year ago • 6 comments

https://nextjs.org/docs/pages/api-reference/next-config-js

CommonJS works just fine with the docs provided but the ecma script does not

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  async redirects() {
    return [
      {
        source:
          "/2021/06/29/simple-telegram-bot-in-python-hosted-easily-on-heroku",
        destination: "/simple-telegram-bot-in-python-hosted-easily-on-heroku",
        permanent: true,
      },
      {
        source: "/2021/07/11/easy-proxy-scraper-and-proxy-usage-in-python",
        destination: "/easy-proxy-scraper-and-proxy-usage-in-python",
        permanent: true,
      },
      {
        source:
          "/2021/05/27/panel-data-econometrics-an-introduction-with-an-example-in-python",
        destination:
          "/panel-data-econometrics-an-introduction-with-an-example-in-python",
        permanent: true,
      },
      {
        source: "/2021/06/06/time-series-data-an-easy-introduction",
        destination: "/time-series-data-an-easy-introduction",
        permanent: true,
      },
      {
        source: "/simple-image-classification-with-efficientnet",
        destination: "/efficientnet-classification",
        permanent: true,
      },
      {
        source: "/page/3",
        destination: "/",
        permanent: true,
      },
      {
        source: "/author/fedotovn19/page/3",
        destination: "/",
        permanent: true,
      },
      {
        source: "/tabular-playground-overfitting-solvers-club",
        destination: "/",
        permanent: true,
      },
      {
        source: "/data-science-playground-solvers-club",
        destination: "/",
        permanent: true,
      },
      {
        source: "/honest_protocol_data_analytics",
        destination: "/data_analytics",
        permanent: true,
      },
      {
        source: "/blog/0",
        destination: "/blog",
        permanent: true,
      },
      {
        source: "/.Unlock",
        destination: "/",
        permanent: true,
      },
    ];
  },
};

const removeImports = require("next-remove-imports")();
module.exports = removeImports({ ...nextConfig });

Pfed-prog avatar Mar 21 '24 14:03 Pfed-prog

@Pfed-prog

// next.config.mjs
import removeImports from 'next-remove-imports'

/** @type {function(import("next").NextConfig): import("next").NextConfig}} */
const removeImportsFun = removeImports({
  // test: /node_modules([\s\S]*?)\.(tsx|ts|js|mjs|jsx)$/,
  // matchImports: "\\.(less|css|scss|sass|styl)$"
});

export default removeImportsFun({
  webpack(config, options) {
    return config
  },
});

jaywcjlove avatar Mar 22 '24 03:03 jaywcjlove

@Pfed-prog

// next.config.mjs
import removeImports from 'next-remove-imports'

/** @type {function(import("next").NextConfig): import("next").NextConfig}} */
const removeImportsFun = removeImports({
  // test: /node_modules([\s\S]*?)\.(tsx|ts|js|mjs|jsx)$/,
  // matchImports: "\\.(less|css|scss|sass|styl)$"
});

export default removeImportsFun({
  webpack(config, options) {
    return config
  },
});

This gives build error

Pfed-prog avatar Mar 22 '24 12:03 Pfed-prog

https://github.com/uiwjs/next-remove-imports/blob/243d8483bffde971465ca3c821201cd72d732ef8/example/esm/next.config.mjs#L1-L17

@Pfed-prog If you provide a reproducible example, I can help you take a look.

jaywcjlove avatar Mar 22 '24 12:03 jaywcjlove

https://github.com/dspytdao/dspyt-homepage/tree/main/dspyt

https://github.com/dspytdao/dspyt-homepage/blob/main/dspyt/next.config.js

I have translated other configs to ecma as well, but the key part of the project is next config

Pfed-prog avatar Mar 22 '24 13:03 Pfed-prog

image

@Pfed-prog Not sure what happened.

jaywcjlove avatar Mar 22 '24 17:03 jaywcjlove

image @Pfed-prog Not sure what happened.

Omg, thank you so much for helping. I am trying to convert this file to ecma and it fails.

Pfed-prog avatar Mar 22 '24 17:03 Pfed-prog