How to copy static files to build directory during the build to access to them during SSR in next.js?

I used the static file in my code like following:

const postsPath = join(process.cwd(), "_posts", "")

It works well in local, but it doesn’t work in production.
When I deployed my code, I faced the following error.

14:40:12.457 ERROR: XDN error - Error in ResponseWriter: {"errno":-2,"syscall":"open","code":"ENOENT","path":"/var/task/_posts/"}

How can I solve this issue?

@jianxing this will help: study webpack config

@ierceg this copy webpack plugin works locally. When I define this:

const { withXDN, withServiceWorker } = require('@xdn/next/config')
const withImages = require('next-images');
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = withXDN(
    webpack(config, options) {
      config.plugins.push(new CopyWebpackPlugin({
        patterns: [
            { from: '_posts', to: '_posts' }
      return config;

I get a copy of those files in .next/_posts/ and .next/serverless/_posts/.

Now how do I access them in the SSR code in production? process.cwd() gives me /var/task/. The _post directory is not there, nor can I read the contents of that directory to figure out where to look.

I suspect the folder is at /var/task/_next/data/s-igIFZeCsERZQCzNdRPv/_posts/ where the ID in the path is the BUILD_ID? Is that right?

@jianxing @ajay After the build, try to find the file in .xdn/lambda subdirectory as that will reflect what will be put into your serverless instance. If the file is there, it should just be a matter of navigating that structure with /var/task as the root.

Thanks, it worked. Will post the full example later.