簡體   English   中英

如何在Meteor項目上組織文件夾和文件?

[英]How to organize folders and files on Meteor project?

創建項目時,我試圖了解Meteor,到目前為止,我發現有些事情很難理解。

1-當他們說我可以創建serverclient文件夾時,我到底打算在哪里創建? .meteor兄弟姐妹? 啟動應用程序時,一切都會在客戶端或服務器的范圍內嗎?還是我需要做其他事情? 如果我在client文件夾中創建了一個foo.js和一個foo函數,是否可以在Meteor.isClient調用foo()且它可以正常工作?

2-我需要創建一個上傳文件夾,以便人們可以上傳他們的東西(圖像)。 那我應該在哪里做呢? 另外,如何獲得項目的絕對路徑並在其中找到此upload文件夾?

在嘗試過程中,我嘗試了以下操作:

fs = Meteor.npmRequire('fs');
__ROOT_APP_PATH__ = fs.realpathSync('.');

但是__ROOT_APP_PATH__.meteor\\local\\build\\programs\\server 相當隱藏吧?

3-我看到有人直接在MongoDB上上傳和保存文件。 這通常是關系數據庫所不具備的。 我們將文件移動到CDN或我們自己的磁盤上的已知文件夾中,並保存該文件的哈希或名稱,以便我們輕松找到它。 Meteor + MongoDB鼓勵了嗎? 為什么我將文件本身保存在Mongo上而不是將其移動到文件夾中?

沒有任何特定的方法,但流星建議以這種方式進行http://docs.meteor.com/#/basic/filestructure

資料夾結構:

both/ (OR lib/)          -- common code for server and client
  |- collections/        -- declare collections (e.g Employer = new Meteor.Collection("employer");)
  |- router     /        -- router code(e.g Router.route(..))

client/                  -- client side code
  |- global/             -- all global variable for client
  |- helpers/            -- global helper for client (for all templates)
  |- plugins/            -- all the plugins code(if you use any)
  |- stylesheets/        -- css / less files
  |- templates/          -- all templates
        |- home.html     -- home template(html)
        |- home.js       -- home template(js)

public/                  -- images/icons/fonts (meteor looking at this file)

server/                  -- server code
  |- methods/            -- server methods/API (e.g Meteor.methods({...}))
  |- publish/            -- publish code from server

這是我遵循的流星項目的基本文件夾結構。 供進一步參考文檔 如有任何問題,請隨時在評論中提問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM