webpack - Next.js 将编译后的 service.worker.ts 文件作为静态文件提供。不允许自定义服务器
问题描述
不是重复的。引用:“我试图在使用 webpack 的非下一个 js 项目中复制它”
就我而言(请参见下面的代码),我使用的是 IN next.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;
}
};
解决方案
推荐阅读
- jmeter - 1 请求发送多次与步进线程组
- makefile - 这些代码行在 makefile 中是什么意思?你能向我解释这个例子吗?
- angular - 在 CKEditor 中使用 ckeditor5-typing 包
- python - Python Pandas Dataframe loop iteration
- amazon-web-services - AWS Data Structure and Stack Suggestion for highly filterable data
- python - how can i add a new line using x.write(input()) in python
- javascript - 将第一个值设置为 Javascript 数组中的键
- r - 使用 R 中的 ggplot 在绘图数据集中获取时间序列
- javascript - Assign different label for each line in line graph for each iteration in js
- javascript - In mongoose, how can i check if all elements in an ObjectId Array exists on database