Permalink
Browse files

Replace RequireJS with Almond during build [fixes #296]

  • Loading branch information...
1 parent e96f741 commit 2cacbeacdab1b1f6b30aaf1af335c78a77b07d6d @marian-r marian-r committed Nov 22, 2015
Showing with 42 additions and 29 deletions.
  1. +0 −4 generators/app/index.js
  2. +30 −25 generators/app/templates/Gruntfile.js
  3. +3 −0 generators/app/templates/index.html
  4. +9 −0 test/test-requirejs.js
@@ -296,10 +296,6 @@ var BackboneGenerator = yeoman.generators.Base.extend({
sassBootstrap: this.sassBootstrap
}
);
-
- this.indexFile = htmlWiring.appendScripts(this.indexFile, 'scripts/main.js', [
- 'bower_components/requirejs/require.js'
- ], {'data-main': 'scripts/main'});
},
setupEnv: function () {
@@ -229,30 +229,35 @@ module.exports = function (grunt) {
dist: {
// Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js
options: {
-<% if (hasCoffee) { -%>
- // `name` and `out` is set by grunt-usemin
+ almond: true,
+
+ replaceRequireScript: [{
+ files: ['<%%= yeoman.dist %>/index.html'],
+ module: 'main'
+ }],
+
+ modules: [{name: 'main'}],
+<% if (hasCoffee) { %>
baseUrl: '.tmp/scripts',
-<% } else { -%>
+<% } else { %>
baseUrl: '<%%= yeoman.app %>/scripts',
-<% } -%>
-<% if (templateFramework !== 'handlebars') { -%>
- wrap: true,
-<% } -%>
- optimize: 'none',
- paths: {
- 'templates': '../../.tmp/scripts/templates',
- 'jquery': '../../<%%= yeoman.app %>/bower_components/jquery/dist/jquery',
- 'underscore': '../../<%%= yeoman.app %>/bower_components/lodash/dist/lodash',
- 'backbone': '../../<%%= yeoman.app %>/bower_components/backbone/backbone'
- },
- // TODO: Figure out how to make sourcemaps work with grunt-usemin
- // https://github.com/yeoman/grunt-usemin/issues/30
- //generateSourceMaps: true,
- // required to support SourceMaps
- // http://requirejs.org/docs/errors.html#sourcemapcomments
- preserveLicenseComments: false,
- useStrict: true
- //uglify2: {} // https://github.com/mishoo/UglifyJS2
+<% } %>
+ mainConfigFile: '<%%= yeoman.app %>/scripts/main.js', // contains path specifications and nothing else important with respect to config
+ dir: '.tmp/scripts',
+
+ optimize: 'none', // optimize by uglify task
+ useStrict: true<% if (templateFramework !== 'handlebars') { %>,
+ wrap: true
+<% } %>
+ }
+ }
+ },
+ uglify: {
+ dist: {
+ files: {
+ '<%%= yeoman.dist %>/scripts/main.js': [
+ '.tmp/scripts/main.js'
+ ]
}
}
},
@@ -518,14 +523,14 @@ module.exports = function (grunt) {
'sass:dist',
<% } -%>
'useminPrepare',
-<% if (includeRequireJS) { -%>
- 'requirejs',
-<% } -%>
'imagemin',
'htmlmin',
'concat',
'cssmin',
+<% if (includeRequireJS) { -%>
+ 'requirejs',
'uglify',
+<% } -%>
'copy',
'rev',
'usemin'
@@ -107,5 +107,8 @@ <h3 class="text-muted"><%= appName %></h3>
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-XXXXX-X');ga('send','pageview');
</script>
+<% if (includeRequireJS) { -%>
+ <script data-main="scripts/main" src="bower_components/requirejs/require.js"></script>
+<% } -%>
</body>
</html>
@@ -119,4 +119,13 @@ describe('Backbone generator with RequireJS', function () {
});
});
});
+
+ describe('creates script tag without usemin block', function() {
+ it('without failure', function() {
+ var unexpectedContent = [
+ ['app/index.html', /<!-- build:js .*? -->(((?!build).|\n)*requirejs)+((?!build).|\n)*?<!-- endbuild -->/i],
+ ];
+ assert.noFileContent(unexpectedContent);
+ });
+ });
});

0 comments on commit 2cacbea

Please sign in to comment.