This repository has been archived by the owner. It is now read-only.

Usemin does not include require.js in the build file #98

Closed
FoxGit opened this Issue Apr 15, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@FoxGit

FoxGit commented Apr 15, 2013

Hi,

I am using requirejs with my project and generated it using Yeoman. All the js files are concatenated, uglified and so on correctly but I still end up having require.js in a seperate file.

Source:
HTML part:

    <!-- build:js main.js -->
    <script data-main="scripts/main" src="components/requirejs/require.js"></script>
    <!-- endbuild -->

Gruntfile part:

// configurable paths
var yeomanConfig = {
    app : 'app',
    dist : 'dist'
};
            useminPrepare : {
                html : '<%= yeoman.app %>/index.html',
                options : {
                    dest : '<%= yeoman.dist %>'
                }
            },
            usemin : {
                html : [ '<%= yeoman.dist %>/{,*/}*.html' ],
                css : [ '<%= yeoman.dist %>/*.css' ],
                options : {
                    dirs : [ '<%= yeoman.dist %>' ]
                }
            },
            requirejs : {
                compile : {
                    options : {
                        optimize : 'none',
                    }
                }
            }

Built HTML file:

<script data-main="main" src="components/requirejs/require.js"></script>

It was working before I upgraded Yeoman. But as the building process is now purely managed via GruntJS I hope I have come to the right place. :) I think I am just missing a configuration somewhere so that require.js is put into the build js file and the HTML file is altered accordingly. Thx in advance

@mysterycommand

This comment has been minimized.

Show comment
Hide comment

mysterycommand commented May 15, 2013

+1

@sleeper

This comment has been minimized.

Show comment
Hide comment
@sleeper

sleeper May 15, 2013

Contributor

Note that as per #112, we're going to deprecate the use of require.js in blocks, in favor of using grunt-requirejs.

Contributor

sleeper commented May 15, 2013

Note that as per #112, we're going to deprecate the use of require.js in blocks, in favor of using grunt-requirejs.

@mysterycommand

This comment has been minimized.

Show comment
Hide comment
@mysterycommand

mysterycommand May 15, 2013

In case it's useful to anyone looking for an answer like, now … I got it sort of, mostly working by adding:

include: '../bower_components/requirejs/require',
mainConfigFile: yeomanConfig.app + '/scripts/config.js',
out: yeomanConfig.dist + '/scripts/app.min.js'

… to the Gruntfile's requirejs.dist.options object, and changing the index.html file from:

<!-- build:js scripts/app.min.js -->
<script data-main="scripts/config" src="bower_components/requirejs/require.js"></script>
<!-- endbuild -->

… to:

<!-- REMOVE THIS AFTER `grunt build` -->
<script data-main="scripts/config" src="bower_components/requirejs/require.js"></script>

<!-- UNCOMMENT THIS AFTER `grunt build` -->
<!-- <script src="scripts/app.min.js"></script> -->

The rev:dist task still picks up that there's a script tag in that last comment, and updates the filename appropriately. Once built, you will get a 404 for require.js, but removing and uncommenting the marked lines fixes that right up … not ideal, but it works for now.

Makes me wonder though, how hard would it be to add usemin task blocks like build:add/remove and build:(un)comment … would have definite utility in this particular case, but also maybe would be good for setting debug or testing flags. Just a thought.

mysterycommand commented May 15, 2013

In case it's useful to anyone looking for an answer like, now … I got it sort of, mostly working by adding:

include: '../bower_components/requirejs/require',
mainConfigFile: yeomanConfig.app + '/scripts/config.js',
out: yeomanConfig.dist + '/scripts/app.min.js'

… to the Gruntfile's requirejs.dist.options object, and changing the index.html file from:

<!-- build:js scripts/app.min.js -->
<script data-main="scripts/config" src="bower_components/requirejs/require.js"></script>
<!-- endbuild -->

… to:

<!-- REMOVE THIS AFTER `grunt build` -->
<script data-main="scripts/config" src="bower_components/requirejs/require.js"></script>

<!-- UNCOMMENT THIS AFTER `grunt build` -->
<!-- <script src="scripts/app.min.js"></script> -->

The rev:dist task still picks up that there's a script tag in that last comment, and updates the filename appropriately. Once built, you will get a 404 for require.js, but removing and uncommenting the marked lines fixes that right up … not ideal, but it works for now.

Makes me wonder though, how hard would it be to add usemin task blocks like build:add/remove and build:(un)comment … would have definite utility in this particular case, but also maybe would be good for setting debug or testing flags. Just a thought.

@FoxGit

This comment has been minimized.

Show comment
Hide comment
@FoxGit

FoxGit May 15, 2013

Alrighty, waiting for usemin 2.0. Thx for the response @sleeper and thx for the workaround @mysterycommand

FoxGit commented May 15, 2013

Alrighty, waiting for usemin 2.0. Thx for the response @sleeper and thx for the workaround @mysterycommand

@FoxGit FoxGit closed this May 15, 2013

@sleeper

This comment has been minimized.

Show comment
Hide comment
@sleeper

sleeper May 15, 2013

Contributor

BTW, usemin 2.0 is in good progress. See #85 for additional information/tracking.

Contributor

sleeper commented May 15, 2013

BTW, usemin 2.0 is in good progress. See #85 for additional information/tracking.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.