diff --git a/package.json b/package.json index 2c26739..ab597a6 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "karma-webpack": "1.7.0", "mocha": "3.0.1", "npm-run-all": "2.3.0", + "offline-plugin": "3.4.2", "opt-cli": "1.5.1", "progress-bar-webpack-plugin": "1.9.0", "rimraf": "2.5.4", diff --git a/src/bootstrap.js b/src/bootstrap.js index 5b32a1b..7b6e4a5 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -1,4 +1,5 @@ /* eslint no-console:0 */ +import {install as offlineInstall} from 'offline-plugin/runtime' import {onLoad} from './app' import {$on} from './helpers' @@ -24,4 +25,7 @@ if (module.hot) { function bootstrap() { $on(window, 'load', onLoad) $on(window, 'hashchange', onLoad) + if (process.env.NODE_ENV === 'production') { + offlineInstall() + } } diff --git a/webpack.config.babel.js b/webpack.config.babel.js index b54be36..f1a278f 100644 --- a/webpack.config.babel.js +++ b/webpack.config.babel.js @@ -7,6 +7,7 @@ const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin') const ExtractTextPlugin = require('extract-text-webpack-plugin') const webpackValidator = require('webpack-validator') const {getIfUtils, removeEmpty} = require('webpack-config-utils') +const OfflinePlugin = require('offline-plugin') module.exports = env => { const {ifProd, ifNotProd} = getIfUtils(env) @@ -45,6 +46,12 @@ module.exports = env => { template: './index.html', inject: 'head', }), + new OfflinePlugin(), + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: ifProd('"production"', '"development"') + } + }), ]), }) if (env.debug) {