production.js (2221B)
- // Note: You must restart bin/webpack-dev-server for changes to take effect
- const webpack = require('webpack');
- const merge = require('webpack-merge');
- const sharedConfig = require('./shared.js');
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
- const OfflinePlugin = require('offline-plugin');
- const { publicPath } = require('./configuration.js');
- const path = require('path');
- module.exports = merge(sharedConfig, {
- output: {
- filename: '[name].js',
- chunkFilename: '[name].js',
- },
- devtool: 'source-map', // separate sourcemap file, suitable for production
- stats: 'normal',
- plugins: [
- new webpack.optimize.UglifyJsPlugin({
- sourceMap: true,
- mangle: true,
- compress: {
- warnings: false,
- },
- output: {
- comments: false,
- },
- }),
- new OfflinePlugin({
- publicPath: publicPath, // sw.js must be served from the root to avoid scope issues
- caches: {
- main: [':rest:'],
- additional: [':externals:'],
- optional: [
- '**/locale_*.js', // don't fetch every locale; the user only needs one
- '**/*_polyfills-*.js', // the user may not need polyfills
- '**/*.woff2', // the user may have system-fonts enabled
- // images/audio can be cached on-demand
- '**/*.png',
- '**/*.jpg',
- '**/*.jpeg',
- '**/*.svg',
- '**/*.mp3',
- '**/*.ogg',
- ],
- },
- externals: [
- '/emoji/1f602.svg', // used for emoji picker dropdown
- '/emoji/sheet.png', // used in emoji-mart
- ],
- excludes: [
- '**/*.map',
- 'stats.json',
- 'report.html',
- // any browser that supports ServiceWorker will support woff2
- '**/*.eot',
- '**/*.ttf',
- '**/*-webfont-*.svg',
- '**/*.woff',
- ],
- ServiceWorker: {
- entry: `imports-loader?process.env=>${encodeURIComponent(JSON.stringify(process.env))}!${encodeURI(path.join(__dirname, '../../app/javascript/mastodon/service_worker/entry.js'))}`,
- cacheName: 'mastodon',
- output: '../assets/sw.js',
- publicPath: '/sw.js',
- minify: true,
- },
- }),
- ],
- });