Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minify service worker script before html inlining (#59) #61

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions template/build/load-minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var fs = require('fs')
var UglifyJS = require('uglify-es')

module.exports = function(filePath) {
var code = fs.readFileSync(filePath, 'utf-8')
var result = UglifyJS.minify(code)
if (result.error) return ''
return result.code
}
5 changes: 3 additions & 2 deletions template/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
var loadMinified = require('./load-minfied')
Copy link

@Gomah Gomah Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anubhav7495 Typo here ☝️

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will push a fix immediately.


var env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
? require('../config/test.env')
Expand Down Expand Up @@ -68,8 +69,8 @@ var webpackConfig = merge(baseWebpackConfig, {
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency',
serviceWorkerLoader: `<script>${fs.readFileSync(path.join(__dirname,
'./service-worker-prod.js'), 'utf-8')}</script>`
serviceWorkerLoader: `<script>${loadMinified(path.join(__dirname,
'./service-worker-prod.js'))}</script>`
}),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
Expand Down
3 changes: 2 additions & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"webpack": "^2.6.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.18.0",
"webpack-merge": "^4.1.0"
"webpack-merge": "^4.1.0",
"uglify-es": "^3.0.25"
},
"engines": {
"node": ">= 4.0.0",
Expand Down