3

Exporting static html files on Next.Js, the href and src directory on HTML is not going to the "_next" folder. If I set it manually by adding ../../ in the index.html, then it works fine. Same for JS files.

Any idea where to pre-configure this before it is exported.

Thanks!

P.s I have a webpack config.

const config = {
  mode: isProd ? "production" : "development",
  entry: {
    index: "./src/index.tsx"
  },
  output: {
    path: `${__dirname}/dist`,
    publicPath: '/',
    filename: "[name].js"
  },
  resolve: {
    extensions: [".js", ".jsx", ".ts", ".tsx"],
    alias: resolveTsAliases(__dirname + "/tsconfig.json")
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "babel-loader",
        exclude: /node_modules/
      },
      {
        test: /\.s[ac]ss$/i,
        use: ["style-loader", "css-loader", "sass-loader"]
      },
      {
        test: /\.(jpg|png)$/,
        use: {
          loader: "url-loader",
          options: {
            limit: 25000
          }
        }
      },
      {
        test: /\.svg$/,
        use: "file-loader"
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "src/index.html"
    }),
    new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
    })
  ]
};

I found another stack overflow thread, but they also manually set their directory, but I need it to work due to a lot of files being exported.

Tried researching on documentations couldn't find the possibility of pre-configuring CSS/JS path for exported files.

4 Answers 4

2

The problem was that it required to run on a live server, so if you host the "/out" folder with all the required files, and running a live server fixes the issue.

Opening the index.html on it owns won't recognize the CSS nor jess files,so just run on a server.

Test on Surge.sh easy as 123.

Sign up to request clarification or add additional context in comments.

Comments

2

you have to add this to your next.config.js

module.exports = {   
assetPrefix: "." 
}

hope this help :)

Comments

0

By adding

module.exports = { basePath: './subfolder', }

this will fix it! If you need to navigate within a subfolder and your css/js not working, this is what your missing in your next.config.js.

Comments

0
module.exports = {   
assetPrefix: "https://www.yoursite.com" 
}

assetPrefix

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.