2013-02-20 13 views
11

मैं डीजेगो के साथ अंत में बैकबोन के साथ एक हाइब्रिड वेब एप्लिकेशन बना रहा हूं।एक हाइब्रिड Django/बैकबोन ऐप के साथ Yeoman/ब्रंच उपकरण का उपयोग कर?

संरचना निम्नानुसार है: मैं Django टेम्पलेट्स में सभी HTML उत्पन्न करता हूं, यह तय करने के लिए कि कौन से टेम्पलेट लौटने के लिए request.is_ajax का उपयोग करें, और आवश्यकतानुसार HTML में खींचने के लिए बैकबोन का उपयोग करें (ऐसा इसलिए है क्योंकि मैं गैर-जावास्क्रिप्ट उपयोगकर्ताओं का समर्थन करना चाहता हूं)।

वैसे भी, मेरा सवाल यह है। मेरी जावा स्क्रिप्ट कोड और अधिक जटिल हो जाता है, मैं अपने आप निम्नलिखित बातें करने में सक्षम होना चाहते हैं:

  • श्रृंखलाबद्ध और कम करने से सीएसएस फ़ाइलें

    • अतुल्यकालिक जावास्क्रिप्ट लोड हो रहा है
    • श्रृंखलाबद्ध और कम करने से JavaScript फ़ाइलों
    • जे एस -linting

    मैं छवि अनुकूलन या पैकेज प्रबंधन के बारे में बहुत चिंतित नहीं हूं। क्या मेरे पास सेटअप के साथ यह संभव है? वर्तमान में यह एक मानक Django अनुप्रयोग है:

    /media 
        /js 
        main.js <-- Backbone code is in here 
        /plugins 
         backbone.js 
         underscore.js 
        /css 
        main.css 
        results.css 
        /img 
    /myapp 
        admin.py 
        models.py 
        views.py 
    /templates 
        /myapp 
        index.html <-- references to all JS and CSS files here 
    

    मुझे यकीन है कि अगर मैं Yeoman (या बस grunt) या Brunch का उपयोग करना चाहिए नहीं कर रहा हूँ, या हो, तो एक सरल तरीका। जो कुछ भी मैं उपयोग करता हूं, मुझे यकीन नहीं है कि क्या इसे js निर्देशिका में छोड़ दिया जा सकता है, या यदि टेम्पलेट का स्थान चीजों को जटिल करेगा।

    वर्तमान में मुझे पता है कि जेएस को असीमित रूप से लोड करने के लिए requ.js का उपयोग कैसे करें, लेकिन मुझे नहीं पता कि कैसे सम्मिलित करना, लिंट इत्यादि - इसलिए एक उपकरण की तलाश है। शायद मुझे सिर्फ एक शेल स्क्रिप्ट लिखनी चाहिए :)

  • उत्तर

    3

    मैं बस कड़वाहट से शुरू करने के लिए सलाह दे सकता हूं। वहाँ अपने सभी जरूरतों के लिए घुरघुराना कार्य कर रहे हैं:

    • grunt-contrib-usemin इच्छा अनुकूलित vers
    • grunt-contrib-uglify के साथ अपने मूल फ़ाइलों के लिए संदर्भ की जगह कम करें अपने जावास्क्रिप्ट
    • grunt-contrib-mincss अपने सीएसएस
    • grunt-contrib-jshint रन पर JSHint कम करें होगा अपने जावास्क्रिप्ट फाइल
    • आवश्यक फ़ाइलों को एक फ़ाइल में संकलित करने के लिए आपकी फ़ाइलों को एसिंक्रोनस और grunt-contrib-requirejs लोड करने के लिए आवश्यक है
    8

    मैं बस ब्रंच से शुरू करने के लिए सलाह दे सकता हूं। ब्रंच गड़बड़ी से आसान है, क्योंकि इसके प्लगइन 500-लाइन-ऑफ-कोड-ग्रंटफाइल लिखने की आवश्यकता के बिना उचित आउट-ऑफ-बॉक्स काम करते हैं। यह भी तेज़ है, आपके ऐप का पुनर्मूल्यांकन तत्काल किया जाएगा।

    आपका सेटअप इस

    public/   # The directory with static files which is generated by brunch. 
        app.js  # Ready to be served via webserver. 
        app.css  # Don’t change it directly, just run `brunch watch --server`. 
        assets/  # And then all changed files in your app dir will be compiled. 
        images/ 
    
    frontend/  # Main brunch application directory. Configurable, of course. 
        app/   # Your code will reside here. 
        assets/  # Static files that shall not be compiled 
         images/ # will be just copied to `public` dir. 
        views/  # Create any subdirectories inside `app` dir. 
         file-1.js # JS files will be automatically concatenated to one file. 
        file-2.js # They will be also usable as modules, like require('file-2'). 
        file-1.css # CSS files will be automatically concatenated to one file. 
        stuff.css # JS and CSS files may be linted before concatenation. 
        tpl.jade # You may have pre-compiled to JS templates. Also with `require`. 
        vendor/  # All third-party libraries should be put here. JS, CSS, anything. 
        scripts/ # They will be included BEFORE your scripts automatically. 
         backbone.js 
         underscore.js 
        package.json # Contains all brunch plugins, like jshint-brunch, css-brunch. 
        config.coffee # All params (you can concat to 2, 5, 10 files etc.) 
           # are set via this config. Just simple, 15 lines-of-code config. 
    

    की तरह लग रहे नए एप्लिकेशन बनाने के लिए, brunch skeletons पर एक नज़र जो बुनियादी boilerplates की तरह हैं ले जाएगा। किसी भी को चुनें, फिर brunch new --skeleton <url> का उपयोग करें, brunch watch --server के साथ लॉन्च ब्रंच वॉचर और आप तैयार हैं। जब आप अपने ऐप को तैनात करना चाहते हैं, तो बस brunch build --optimize के साथ सामान बनाएं जो स्वचालित रूप से फ़ाइलों को कम कर देगा।

    संबंधित मुद्दे