Navigation Menu

Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Load order not preserved when using arrays for joinTo? #1610

Closed
dsignr opened this issue Dec 30, 2016 · 20 comments
Closed

Load order not preserved when using arrays for joinTo? #1610

dsignr opened this issue Dec 30, 2016 · 20 comments

Comments

@dsignr
Copy link

dsignr commented Dec 30, 2016

Description

When using an array for joinTo, the load order doesn't seem to be preserved, even with an order key specified.

files:
    javascripts:
      joinTo:
        '/js/application.js': [
                                /app\/coffeescript\/vendor/,
                                /app\/coffeescript\/application/
                              ]
        '/js/pages.js': [
                          /app\/coffeescript\/vendor/,
                          /app\/coffeescript\/pages/
                        ]
      order:
        before: [
          /app\/coffeescript\/vendor/
        ]

Expected behavior

I would like the files in my vendor directory (jQuery, Bootstrap) be loaded before the app scripts. Just in case this helps, I also have:

  npm: enabled: false

  modules:
    wrapper: false
    definition: false

Actual behavior

What happens is that the order of concatenation is wrong:

app scripts are loaded first
jquery and semantic are loaded after my app scripts thus throwing an error.

Environment

  1. Brunch: 2.7.4
  2. Node: v6.2.1
  3. NPM: 3.9.3
  4. Operating system: Mac OS X, latest

package.json contents

{
  "name": "brunch-app",
  "description": "Description",
  "author": "Your Name",
  "version": "0.1.0",
  "repository": {
    "type": "git",
    "url": ""
  },
  "scripts": {
    "start": "brunch watch --server",
    "build": "brunch build --production"
  },
  "dependencies": {},
  "devDependencies": {
    "brunch": "^2.0.0",
    "javascript-brunch": "^2.0.0",
    "css-brunch": "^2.0.0",
    "uglify-js-brunch": "^2.0.0",
    "clean-css-brunch": "^2.0.0",
    "auto-reload-brunch": "^2.0.0",
    "javascript-brunch": ">= 1.0 < 1.4",
    "coffee-script-brunch": ">= 1.0 < 1.4",
    "sass-brunch": "^2.7.0"
  }
}

brunch config contents

# See http://brunch.io for documentation.
module.exports =

  files:
    javascripts:
      joinTo:
        '/js/application.js': [
                                /app\/coffeescript\/vendor/,
                                /app\/coffeescript\/application/
                              ]
        '/js/pages.js': [
                          /app\/coffeescript\/vendor/,
                          /app\/coffeescript\/pages/
                        ]
      order:
        before: [
          /app\/coffeescript\/vendor/
        ]
    stylesheets:
      joinTo:
        '/css/application.css': [
                                  /app\/sass\/vendor/,
                                  /app\/sass\/application/
                                ]
        '/css/pages.css':  [
                              /app\/sass\/vendor/,
                              /app\/sass\/pages/
                           ]
      order:
        before: [
          /app\/sass\/vendor\/semantic/
        ]


  paths: public: '/priv/static'

  npm: enabled: false

  modules:
    wrapper: false
    definition: false

  sourceMaps: false

Other useful files, when present (log, bower.json etc.)

If there's an unexpected error during brunch build/brunch watch, please attach the compilation log with the debug flag (-d) and stack traces enabled (export LOGGY_STACKS=true).

If something worked with previous versions of brunch, but stopped with a newer one, please include these details as well.

brunch:config Trying to load brunch-config +0ms
  brunch:plugins Loaded plugins: javascript-brunch, css-brunch, auto-reload-brunch, coffee-script-brunch, sass-brunch +330ms
  brunch:watch add package.json +20ms
  brunch:watch add brunch-config.coffee +1ms
  brunch:watch add test/test_helper.exs +4ms
  brunch:list Reading test/test_helper.exs +1ms
  brunch:watch add app/assets/README.md +2ms
  brunch:asset Init app/assets/README.md directory=app/assets/ destPath=priv/static/README.md rel=README.md +1ms
  brunch:watch add app/assets/index.html +1ms
  brunch:asset Init app/assets/index.html directory=app/assets/ destPath=priv/static/index.html rel=index.html +1ms
  brunch:watch add app/coffeescript/application.coffee +0ms
  brunch:list Reading app/coffeescript/application.coffee +0ms
  brunch:watch add app/coffeescript/pages.coffee +1ms
  brunch:list Reading app/coffeescript/pages.coffee +0ms
  brunch:watch add app/fonts/icons.eot +0ms
  brunch:list Reading app/fonts/icons.eot +0ms
  brunch:watch add app/fonts/icons.svg +1ms
  brunch:list Reading app/fonts/icons.svg +0ms
  brunch:watch add app/fonts/icons.ttf +0ms
  brunch:list Reading app/fonts/icons.ttf +0ms
  brunch:watch add app/fonts/icons.woff +0ms
  brunch:list Reading app/fonts/icons.woff +0ms
  brunch:watch add app/fonts/icons.woff2 +0ms
  brunch:list Reading app/fonts/icons.woff2 +0ms
  brunch:watch add app/images/flags.png +1ms
  brunch:list Reading app/images/flags.png +0ms
  brunch:watch add app/sass/application.sass +0ms
  brunch:list Reading app/sass/application.sass +1ms
  brunch:watch add app/sass/pages.sass +0ms
  brunch:list Reading app/sass/pages.sass +1ms
  brunch:watch add test/controllers/entity_controller_test.exs +1ms
  brunch:list Reading test/controllers/entity_controller_test.exs +0ms
  brunch:watch add test/controllers/page_controller_test.exs +0ms
  brunch:list Reading test/controllers/page_controller_test.exs +0ms
  brunch:watch add test/models/page_test.exs +2ms
  brunch:list Reading test/models/page_test.exs +0ms
  brunch:watch add test/models/entity_test.exs +0ms
  brunch:list Reading test/models/entity_test.exs +1ms
  brunch:watch add test/support/channel_case.ex +0ms
  brunch:list Reading test/support/channel_case.ex +0ms
  brunch:watch add test/support/conn_case.ex +0ms
  brunch:list Reading test/support/conn_case.ex +0ms
  brunch:watch add test/support/model_case.ex +0ms
  brunch:list Reading test/support/model_case.ex +0ms
  brunch:watch add test/views/error_view_test.exs +1ms
  brunch:list Reading test/views/error_view_test.exs +0ms
  brunch:watch add test/views/layout_view_test.exs +0ms
  brunch:list Reading test/views/layout_view_test.exs +0ms
  brunch:watch add test/views/page_view_test.exs +0ms
  brunch:list Reading test/views/page_view_test.exs +0ms
  brunch:watch add app/coffeescript/vendor/jquery-3.1.1.min.js +9ms
  brunch:list Reading app/coffeescript/vendor/jquery-3.1.1.min.js +0ms
  brunch:watch add app/coffeescript/vendor/semantic.min.js +0ms
  brunch:list Reading app/coffeescript/vendor/semantic.min.js +0ms
  brunch:watch add app/sass/vendor/semantic.min.css +1ms
  brunch:list Reading app/sass/vendor/semantic.min.css +0ms
  brunch:asset Copied app/assets/README.md +3ms
  brunch:asset Copied app/assets/index.html +1ms
  brunch:file Init app/coffeescript/application.coffee: isntModule=false isWrapped=true +2ms
  brunch:pipeline Compiling app/coffeescript/application.coffee @ CoffeeScriptCompiler +2ms
  brunch:list Compiled app/coffeescript/application.coffee +7ms
  brunch:file Init app/coffeescript/pages.coffee: isntModule=false isWrapped=true +0ms
  brunch:pipeline Compiling app/coffeescript/pages.coffee @ CoffeeScriptCompiler +1ms
  brunch:list Compiled app/coffeescript/pages.coffee +13ms
  brunch:file Init app/sass/application.sass: isntModule=false isWrapped=false +8ms
  brunch:pipeline Compiling app/sass/application.sass @ SassCompiler +0ms
  brunch:file Init app/sass/pages.sass: isntModule=false isWrapped=false +4ms
  brunch:pipeline Compiling app/sass/pages.sass @ SassCompiler +1ms
  brunch:watch add app/sass/components/common/header.sass +3ms
  brunch:list Reading app/sass/components/common/header.sass +0ms
  brunch:watch add app/sass/components/common/sidebar.sass +1ms
  brunch:list Reading app/sass/components/common/sidebar.sass +0ms
  brunch:file Init app/coffeescript/vendor/jquery-3.1.1.min.js: isntModule=true isWrapped=true +1ms
  brunch:pipeline Compiling app/coffeescript/vendor/jquery-3.1.1.min.js @ JavaScriptCompiler +0ms
  brunch:pipeline Compiling app/coffeescript/vendor/jquery-3.1.1.min.js @ AutoReloader +1ms
  brunch:list Compiled app/coffeescript/vendor/jquery-3.1.1.min.js +0ms
  brunch:file Init app/coffeescript/vendor/semantic.min.js: isntModule=true isWrapped=true +1ms
  brunch:pipeline Compiling app/coffeescript/vendor/semantic.min.js @ JavaScriptCompiler +1ms
  brunch:pipeline Compiling app/coffeescript/vendor/semantic.min.js @ AutoReloader +0ms
  brunch:list Compiled app/coffeescript/vendor/semantic.min.js +1ms
  brunch:file Init app/sass/vendor/semantic.min.css: isntModule=true isWrapped=false +10ms
  brunch:pipeline Compiling app/sass/vendor/semantic.min.css @ CSSCompiler +1ms
  brunch:list Compiled app/sass/vendor/semantic.min.css +1ms
  brunch:file Init app/sass/components/common/header.sass: isntModule=false isWrapped=false +25ms
  brunch:pipeline Compiling app/sass/components/common/header.sass @ SassCompiler +1ms
  brunch:file Init app/sass/components/common/sidebar.sass: isntModule=false isWrapped=false +1ms
  brunch:pipeline Compiling app/sass/components/common/sidebar.sass @ SassCompiler +1ms
  brunch:pipeline Dependencies app/sass/application.sass @ SassCompiler +2s
  brunch:list Compiled app/sass/components/common/header.sass +17ms
  brunch:pipeline Dependencies app/sass/pages.sass @ SassCompiler +0ms
  brunch:list Compiled app/sass/application.sass +1ms
  brunch:pipeline Dependencies app/sass/components/common/sidebar.sass @ SassCompiler +0ms
  brunch:list Compiled app/sass/components/common/sidebar.sass +1ms
  brunch:list Compiled app/sass/pages.sass +20ms
30 Dec 13:29:07 - error: Compiling of app/sass/components/common/header.sass failed. WARNING on line 1:
This selector doesn't have any properties and will not be rendered.
 
30 Dec 13:29:07 - warn: app/sass/components/common/sidebar.sass compiled, but not written. Check your stylesheets.joinTo config
  brunch:write Writing 4/4 files +80ms
  brunch:generate Concatenating [app/coffeescript/vendor/jquery-3.1.1.min.js, app/coffeescript/vendor/semantic.min.js, app/coffeescript/application.coffee] => priv/static/js/application.js +9ms
  brunch:generate Concatenating [app/coffeescript/vendor/jquery-3.1.1.min.js, app/coffeescript/vendor/semantic.min.js, app/coffeescript/pages.coffee] => priv/static/js/pages.js +9ms
  brunch:generate Concatenating [app/sass/vendor/semantic.min.css, app/sass/application.sass] => priv/static/css/application.css +2ms
  brunch:generate Concatenating [app/sass/vendor/semantic.min.css, app/sass/pages.sass] => priv/static/css/pages.css +7ms
  brunch:generate Writing priv/static/js/application.js +6ms
  brunch:generate Writing priv/static/js/pages.js +1ms
  brunch:generate Writing priv/static/css/application.css +0ms
  brunch:generate Writing priv/static/css/pages.css +0ms

P.S I come from a rails background, so, if I missed something basic, sorry 👍

@denysdovhan
Copy link
Contributor

Hi, @dsignr! Glad to help you!

I'm trying to reproduce your issue. Could you, please, create a repo that reproduce your bug. That would save my and your time. Definitely, problem is hidden in lib/fs_utils/generate.js or lib/fs_utils/write.js.

I hope I can make a hotfix for you. Waiting for you response.

@dsignr
Copy link
Author

dsignr commented Jan 2, 2017

Hi @denysdovhan, thank you for the quick response!

Here is the repo: https://github.com/dsignr/brunch-issue-report

Thank you and have a wonderful new year :) 👍

@denysdovhan
Copy link
Contributor

Gonna take a look at this ASAP.

Happy holidays, @dsignr !

@dsignr
Copy link
Author

dsignr commented Jan 3, 2017

@denysdovhan Ok, thank you so much! :) 👍

@denysdovhan
Copy link
Contributor

Oh my, I've spend almost 2 hours trying to understand why your repo do not build anything an gives me EACCES error. The cause is / in config.

That's just by the way, to let you know I'm working on it.

@denysdovhan
Copy link
Contributor

Hey, @dsignr! Try to build your project with the latest version of Brunch from master. Works well for me.

package.json:

"devDependencies": {
-   "brunch": "^2.0.0",
+   "brunch": "brunch/brunch",
    "javascript-brunch": "^2.0.0",
    "css-brunch": "^2.0.0",
    "uglify-js-brunch": "^2.0.0",
    "clean-css-brunch": "^2.0.0",
    "auto-reload-brunch": "^2.0.0",
    "javascript-brunch": ">= 1.0 < 1.4",
    "coffee-script-brunch": ">= 1.0 < 1.4",
    "sass-brunch": "^2.7.0"
  }

I believe that will help.

@denysdovhan
Copy link
Contributor

@dsignr take a look at my version of your repo. Compare with your. Mine works for me as expected.

@dsignr
Copy link
Author

dsignr commented Jan 7, 2017

Wow, that was quite a detailed analysis and fix! Thanks a ton @denysdovhan :) much appreciated!! Wish you the best for this new year :)

Closing this, since it's fixed.. 👍

@dsignr dsignr closed this as completed Jan 7, 2017
@denysdovhan
Copy link
Contributor

@dsignr thank you for reporting! Glad to help you. Feel free to open issues if you have any problem with Brunch.

@dsignr
Copy link
Author

dsignr commented Jan 8, 2017

No @denysdovhan, Thank YOU for your time. As someone who comes from Asset Pipeling, at first I didn't get brunch, but now I don't think I'll be going back haha 💃

@dsignr
Copy link
Author

dsignr commented Jan 14, 2017

Hi @denysdovhan this issue persists for me on a new project. Things I've tried:

  1. Remove '/'
  2. Use "brunch": "brunch/brunch" in package.json.
  3. I tried to have a look at your repo, but since it's deleted I don't have access to it's fixes. (I even checked our archive.org with no luck :( )

I've created another repo: https://github.com/dsignr/brunch-issue-report-1610

The idea here is

  1. I want jQuery to be loaded before all other files.
  2. Ideally, I don't want a separate vendor.js (although my config specifies one).I would like to package everything into just one app.js.
  3. I would like to minify the output produced, but that's not happening either.

Thank you for your time :)

@dsignr dsignr reopened this Jan 14, 2017
@denysdovhan
Copy link
Contributor

Sure, gonna take a look at your problem.

@denysdovhan
Copy link
Contributor

denysdovhan commented Jan 16, 2017

@dsignr I've sent a PR with fixes that work for me: dsignr/brunch-issue-report-1610#1

We released a new version of Brunch — v.2.10.0, so it's better to use the version from NPM, instead of master.

I want jQuery to be loaded before all other files.

That works thanks for order.before option.

I don't want a separate vendor.js

Just keep only one entry point (js/app.js in your case).

I would like to minify the output

Works for me with brunch@2.10.0. Just use brunch build --production or brunch b -p

I believe that will help you. Also, I'd suggest you to use wrapping modules, because it's more safety that exposing everything into global scope. Moreover, better to use source maps — it's much more easier to debug using them. In any case, up to you.

Thank you for reporting!

@dsignr
Copy link
Author

dsignr commented Jan 16, 2017

Hi @denysdovhan ,
Thanks for this, will look into it. As for Sourcemaps and Module-wrapping, in Rails we were not exposed to this as we had asset pipeline, so which is why I wasn't familiar. But seems like they add lot of benefits and I will consider using them, moving forward, thanks to you :)

Gonna merge the PR now and update you very soon if it's resolved. Thanks again! :)

@denysdovhan
Copy link
Contributor

@dsignr don't forget to close this issue

@dsignr
Copy link
Author

dsignr commented Jan 18, 2017

@denysdovhan The first time I built it (after modifying my settings as per recommendation), it still didn't order them as expected, but, after a couple of runs, it now works fine! Gonna close this issue for now and will report back if things go south. Thanks a ton for your excellent support @denysdovhan!

@dsignr dsignr closed this as completed Jan 18, 2017
@dsignr dsignr reopened this Jan 27, 2017
@dsignr
Copy link
Author

dsignr commented Jan 27, 2017

Sorry, this issue still persists. Strangely enough, it works on one machine, but fails on another. This was also tried by another member and confirmed to not working. More context: https://gitter.im/brunch/brunch

@denysdovhan
Copy link
Contributor

@dsignr goddamn. Please, wrap everything in repo, if you could.

Also, are you sure both of those machines are using the same version of Brunch and plugins?

@dsignr
Copy link
Author

dsignr commented Jan 29, 2017

Hi @denysdovhan, it's the same repo (https://github.com/dsignr/brunch-issue-report-1610), same settings, nothing has changed, except when I tested it on another machine, I discovered it doesn't work, the fixes posted here don't work. Versions are the same too. So, I posted a question on brunch and a member on chat also tested it and verified it doesn't work :( Will be happy to share more info.

@dsignr
Copy link
Author

dsignr commented Feb 3, 2017

I think this issue is relevant to this as well: #1121. I got hit by 1121 yesterday. After finally debugging, it seems my other machine was running NPM version 3.9.3 and my current machine was running 4.1.2. Downgrading to 3.9.3 resolved a lot of headaches, but, I will report back soon. This is my way of telling you I'm working on it :)

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

No branches or pull requests

3 participants