Oracle JET 使用RequireJS第三方工具或庫引入

來源:互聯網
上載者:User

標籤:添加   rac   .config   exports   需要   style   腳手架   library   ejs   

  在 Oracle JET 應用程式中使用 RequireJS 添加第三方工具或庫。

  步驟:

  1.如果使用工具架構腳手架,需要一下操作。

    a.使用 npm 安裝你需要的庫。

      npm install my-library --save

    b.在 script/grunt/config 目錄中,在 oraclejet-build.js 中找到 copyCustomLibsToStaging 更新代碼。

      把注釋去掉。並更改:

copyCustomLibsToStaging: {    fileList: [              {cwd:‘node_modules/my-library/‘,               src: [‘*‘],               dest: ‘web/js/libs/my-library‘ }              ]},

    c.在 src/js 目錄中,在 main-release-paths.json  檔案中添加新的庫。使用 min 版本。當構建發行時會使用此檔案。

{    "knockout": "libs/knockout/knockout-x.x.x",    "jquery": "libs/jquery/jquery-x.x.x.min",    ... contents omitted    "my-library": "libs/my-library/my-library.min"}

 

  2.如果沒有使用工具架構構建,直接在 js/libs 目錄中添加新的庫和附帶檔案。

 

  3.執行完上一步後,使用 RequierJS ,在 main.js 中 requirejs.config 中添加路徑,如需要使用則在 require 中定義。

requirejs.config({  // 添加新的庫的路徑  paths:   {    ‘knockout‘: ‘libs/knockout/knockout-3.4.0‘,    ‘jquery‘: ‘libs/jquery/jquery-3.1.0.min‘,    ... contents omitted    ‘text‘: ‘libs/require/text‘,    ‘my-library‘: ‘libs/my-library/my-library  },  // 若不是AMD模組,則在這裡添加新的庫需要的內容  shim: {    ‘jquery‘: {      exports: [‘jQuery‘, ‘$‘]    }  },  require([‘ojs/ojcore‘, ‘knockout‘, ‘jquery‘, ‘my-library‘],  function(oj, ko, $) // 回呼函數,在所有模組載入後執行  {      // 這裡添加使用代碼  });

 

Oracle JET 使用RequireJS第三方工具或庫引入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.