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

UMD tests #13843

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
21 changes: 19 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module.exports = function (grunt) {
' */\n',
// NOTE: This jqueryCheck code is duplicated in customizer.js; if making changes here, be sure to update the other copy too.
jqueryCheck: 'if (typeof define == \'undefined\' && typeof exports == \'undefined\' && typeof jQuery == \'undefined\') { throw new Error(\'Bootstrap\\\'s JavaScript requires jQuery\') }\n\n',
umdWrap: '(function (o_o) {\n' +
' typeof define == \'function\' && define.amd ? define([\'jquery\'], o_o) :\n' +
' typeof exports == \'object\' ? o_o(require(\'jquery\')) : o_o(jQuery)\n' +
'})(function ($) {\n\n',

// Task configuration.
clean: {
Expand Down Expand Up @@ -87,8 +91,21 @@ module.exports = function (grunt) {

concat: {
options: {
banner: '<%= banner %>\n<%= jqueryCheck %>',
stripBanners: false
banner: '<%= banner %>\n<%= jqueryCheck %>\n<%= umdWrap %>',
footer: '});\n',
stripBanners: false,
process: function (src) {
var umd = '\n\n' +
' (function (o_o) {\n' +
' typeof define == \'function\' && define.amd ? define([\'jquery\'], o_o) :\n' +
' typeof exports == \'object\' ? o_o(require(\'jquery\')) : o_o(jQuery)\n' +
' })(function ($) {'

var footer = ' })\n\n' +
'}();\n'

return src.replace(umd, '').replace(footer, '}();\n')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should use RegExp.quote here?
Yeah, hacky indeed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why would we need that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

process runs before each file is added to the concatenated output, so unless the UMD stuff is included twice in a source file, I don't see a problem.

}
},
bootstrap: {
src: [
Expand Down
9,205 changes: 9,205 additions & 0 deletions js/tests/umd/browserify/concatenated/bundle.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions js/tests/umd/browserify/concatenated/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Browserify concatenated</title>
<link rel="stylesheet" type="text/css" href="../../../../../dist/css/bootstrap.min.css">
</head>
<body>

<div class="container">

<div class="page-header">
<h1>Tooltip <small>Bootstrap Visual Test</small></h1>
</div>

<p class="muted" style="margin-bottom: 0;">Tight pants next level keffiyeh <a href="#" data-toggle="tooltip" title="" data-original-title="Default tooltip">you probably</a> haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel <a href="#" data-toggle="tooltip" title="" data-original-title="Another tooltip">have a</a> terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A really ironic artisan <a href="#" data-toggle="tooltip" title="" data-original-title="Another one here too">whatever keytar</a>, scenester farm-to-table banksy Austin <a href="#" data-toggle="tooltip" title="" data-original-title="The last tip!">twitter handle</a> freegan cred raw denim single-origin coffee viral.
</p>
<hr>
<p>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="" data-original-title="Tooltip on left">Tooltip on left</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Tooltip on top</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="right" title="Tooltip on right">Tooltip on right</button>
</p>

</div>

<script src="bundle.js"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions js/tests/umd/browserify/concatenated/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var $ = require('jquery')
require('../../../../../dist/js/bootstrap.min.js')

$('[data-toggle="tooltip"]').tooltip()
Loading