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

Fixing js minimization and removing sourcemaps in production #100

Merged
merged 4 commits into from
Mar 24, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ app.yaml
.DS_Store
.publish/
.vscode/
deploy.sh
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
- [Useful commands](docs/commands.md)
- [Description of files in this directory](docs/file-appendix.md)

Message Count
Conversation Count
---

1. Use the API Gateway endpoint to get the lastest value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, I like lastest as a word

1. Use the API Gateway endpoint to get the latest value.
1. Update [`config.js`](app/scripts/config.js)
24 changes: 13 additions & 11 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h1>Media</h1>
<hr />

<p>
&copy; 2013&nbsp;-
&copy; 2013&nbsp;-&nbsp;
<script>
document.write(new Date().getFullYear());
</script>&nbsp;Crisis Text Line
Expand All @@ -201,18 +201,20 @@ <h1>Media</h1>

<!-- Register new javascript files here and in gulpfile.babel.js -->

<script src="faq.js"></script>
<script src="/faq.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
<script src="scripts/config.js"></script>
<script src="scripts/lib/d3.cloud.js"></script>
<script src="scripts/lib/toggle.js"></script>
<script src="scripts/sections/conversation-count.js"></script>
<script src="scripts/sections/visualizations.js"></script>
<script src="scripts/sections/word-cloud.js"></script>
<script src="scripts/sections/faq.js"></script>
<script src="scripts/main.js"></script>
<script src="scripts/wst.js"></script>
<!-- build:js scripts/main.min.js -->
<script type="text/javascript" src="/scripts/config.js"></script>
<script type="text/javascript" src="/scripts/lib/d3.cloud.js"></script>
<script type="text/javascript" src="/scripts/lib/toggle.js"></script>
<script type="text/javascript" src="/scripts/sections/conversation-count.js"></script>
<script type="text/javascript" src="/scripts/sections/visualizations.js"></script>
<script type="text/javascript" src="/scripts/sections/word-cloud.js"></script>
<script type="text/javascript" src="/scripts/sections/faq.js"></script>
<script type="text/javascript" src="/scripts/main.js"></script>
<script type="text/javascript" src="/scripts/wst.js"></script>
<!-- endbuild -->
</body>

</html>
2 changes: 1 addition & 1 deletion app/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
conversations: {
// count must be an integer
fallbackConversationCount: 4873330,
fallbackConversationCount: 5680775,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated 👍

},
};
})(window);
14 changes: 4 additions & 10 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,23 @@ gulp.task('scripts', gulp.series(() =>
'./app/scripts/wst.js',
'./app/scripts/config.js',
'./app/scripts/lib/*.js',
// './node_modules/carousel-js/dist/carousel.js', TODOCAROUSEL
'./app/scripts/sections/*.js',
'./app/scripts/main.js'
])
], {base: './app/scripts/'})
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with some of this specific gulp configuration, but running it locally it seems like it works 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had updated gulp in a previous PR. There was an issue with changing the relative paths of the js files if the base was not provided.

.pipe($.newer('.tmp/scripts'))
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.sourcemaps.write())
.pipe(gulp.dest('.tmp/scripts'))
.pipe($.concat('main.min.js'))
.pipe($.uglify({ preserveComments: 'some' }))
// Output files
.pipe($.size({ title: 'scripts' }))
.pipe($.sourcemaps.write('.'))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure why this was running twice, but we don't need it for production deploys.

.pipe(gulp.dest('dist/scripts'))
.pipe(gulp.dest('./dist/scripts/'))
));

// Scan your HTML for assets & optimize them
gulp.task('html', gulp.series(() => {
return gulp.src('app/**/*.html')
.pipe($.useref({
searchPath: '{.tmp,app}',
noAssets: true
searchPath: '{.tmp,app}'
}))

// Minify any HTML
Expand Down Expand Up @@ -216,7 +210,7 @@ gulp.task('generate-service-worker', gulp.series('copy-sw-scripts', () => {
}));

// Build production files, the default task
gulp.task('default', gulp.series('clean', 'styles', 'lint', 'html', 'scripts', 'images', 'copy', 'generate-service-worker'));
gulp.task('default', gulp.series('clean', 'styles', 'lint', 'scripts', 'images', 'html', 'copy', 'generate-service-worker'));

// Build and serve the output from the dist build
gulp.task('serve:dist', gulp.series('default', () =>
Expand Down