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;
}
};