Next.js将已编译的service.worker.ts文件作为静态文件提供。不允许自定义服务器

时间:2020-04-22 11:12:46

标签: webpack next.js webpack-dev-server

Not a duplicate。 Quote:“我正在尝试在使用webpack的非下一个js项目中复制此代码”


就我而言(请参见下面的代码),我正在使用INnext.js。我希望将已编译的service.worker.js文件作为公共文件夹中的文件来提供。但就我而言,service.worker.ts文件位于public/文件夹之外。并且它首先被webpack编译。

我应将编译后的service.worker.ts文件的结果放在哪里?目的是能够通过mydomain.com/service.worker.js访问它。也许我使用了错误的配置?也许应该使用webpackDevMiddleware来完成?

const nectConfig = {
  distDir: 'dist',
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    const newConfig = {
      ...config,
      entry: function() {
        return config.entry().then(entry => {
          return {
            ...entry,
            /* where should the output be, so that the service-worker.js file
             can be accessed like any other file under the public/ directory?*/
            './public/service-worker.js': './service-worker.ts'
          };
        });
      },
      output: { ...config.output, globalObject: 'self' }
    };
    return newConfig;
  }
};

0 个答案:

没有答案
相关问题