通过webpack构建服务工作者文件

时间:2017-02-17 14:11:55

标签: webpack service-worker

我的webpack配置看起来非常像这样 -

  entry: {
    main: './src/lib/bootstrap.ts',
    sw: './src/sw/sw-bootstrap.ts'
  },
  output: {
    path: path.resolve(__dirname, 'public'),
    filename: '[name]-[chunkhash].js'
  }

在我的情况下,我希望sw-bootstrap没有附加chunkhash

1 个答案:

答案 0 :(得分:0)

您可以通过将Webpack的CommonChunksPlugin与条目结合使用来实现这一目标:

<强> webpack.config.js

const path = require('path');
const webpack = require('webpack');

const config = {
  entry: {
    main: './src/lib/bootstrap.ts',
    sw: './src/sw/sw-bootstrap.ts'
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: 'sw',
      chunks: ['sw'], // Use here the same keys as under "entry"
      filename: '[name].js'
    })
  ],
  output: {
    path: path.resolve(__dirname, 'public'),
    filename: '[name]-[chunkhash].js'
  }
};