├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Henry Li 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #FORE MORE INFORMATION, PLEASE VISIT [babel-plugin-ui5](https://github.com/MagicCube/babel-plugin-ui5) 2 | 3 | 4 | 5 | 6 | 7 | 8 | # ui5-loader 9 | An UNOFFICIAL experimental Webpack loader for SAP UI5. Together with my Babel 10 | plugin(https://github.com/MagicCube/babel-plugin-ui5), you are abel to use 11 | Webpack + Babel to build your next generation UI5 applications. 12 | 13 | ## Usage 14 | ### 1. Install babel-preset-ui5 15 | Please refer to [babel-preset-ui5](https://github.com/MagicCube/babel-preset-ui5). 16 | 17 | ### 2. Install ui5-loader 18 | ```sh 19 | $ npm install --save-dev ui5-loader 20 | ``` 21 | 22 | ### 3. Configure webpack.config.js 23 | ```javascript 24 | { 25 | ... 26 | module: { 27 | loaders: [ 28 | { 29 | test: /\.js$/, 30 | exclude: /(node_modules|bower_components)/, 31 | loaders: [ 32 | "ui5-loader?sourceRoot=./src", 33 | "babel-loader?sourceRoot=./src" 34 | ] 35 | } 36 | ] 37 | } 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const fs = require("fs"); 4 | const path = require("path"); 5 | const loaderUtils = require("loader-utils"); 6 | 7 | let loaderOptions = null; 8 | 9 | function ui5Loader(source, map) 10 | { 11 | this.cacheable(); 12 | 13 | if (!source) 14 | { 15 | return this.callback(null, source, map); 16 | } 17 | 18 | loaderOptions = loaderUtils.parseQuery(this.query); 19 | if (!loaderOptions.sourceRoot) 20 | { 21 | loaderOptions.sourceRoot = "./"; 22 | } 23 | const webpackRemainingChain = loaderUtils.getRemainingRequest(this).split('!'); 24 | const filename = webpackRemainingChain[webpackRemainingChain.length - 1]; 25 | 26 | let groups = source.match(/sap\.ui\.define\(["'].+]/); 27 | if (groups && groups.length > 0) 28 | { 29 | const definePart = groups[0]; 30 | if (!definePart.endsWith("[]")) 31 | { 32 | groups = definePart.match(/\[(.+)\]/); 33 | if (groups && groups.length > 0) 34 | { 35 | const group = groups[1]; 36 | let dependencies = group.split(", ").map(d => d.replace(/["']/g, "")); 37 | const requires = []; 38 | 39 | dependencies = dependencies.map(d => { 40 | const absPath = resolveModule(d, filename); 41 | if (absPath !== null) 42 | { 43 | requires.push(`require("${absPath}");`); 44 | } 45 | }); 46 | 47 | source = requires.join("") + source; 48 | } 49 | } 50 | } 51 | 52 | this.callback(null, source, map); 53 | }; 54 | 55 | function resolveModule(modulePath, sourceFilename) 56 | { 57 | const sourceRoot = path.resolve(loaderOptions.sourceRoot ? loaderOptions.sourceRoot : process.cwd()); 58 | let absPath = path.resolve(sourceRoot, "./" + modulePath); 59 | if (!absPath.endsWith(".js")) 60 | { 61 | absPath += ".js"; 62 | } 63 | if (fs.existsSync(absPath)) 64 | { 65 | let relativePath = path.relative(path.dirname(sourceFilename), absPath); 66 | if (!relativePath.startsWith(".")) 67 | { 68 | relativePath = "./" + relativePath; 69 | } 70 | relativePath = relativePath.replace(/\\/g, "/"); 71 | return relativePath; 72 | } 73 | else 74 | { 75 | if (!modulePath.startsWith("sap/ui/base")) 76 | { 77 | console.warn(`WARN: Dependency "${modulePath}" of "${path.relative(sourceRoot, sourceFilename)}" is not found in ${sourceRoot}.`); 78 | } 79 | return null; 80 | } 81 | } 82 | 83 | module.exports = ui5Loader; 84 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ui5-loader", 3 | "version": "1.0.6", 4 | "description": "An UNOFFICIAL experimental Webpack loader for SAP UI5. Together with my Babel plugin(https://github.com/MagicCube/babel-plugin-ui5), you are abel to use Webpack + Babel to build your next generation UI5 applications.", 5 | "main": "index.js", 6 | "keywords": [ 7 | "ui5", 8 | "sap", 9 | "sapui5", 10 | "openui5", 11 | "webpack", 12 | "loader" 13 | ], 14 | "scripts": {}, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/MagicCube/ui5-loader.git" 18 | }, 19 | "author": "Henry Li ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/MagicCube/ui5-loader/issues" 23 | }, 24 | "homepage": "https://github.com/MagicCube/ui5-loader#readme", 25 | "dependencies": { 26 | "loader-utils": "^0.2.15" 27 | } 28 | } 29 | --------------------------------------------------------------------------------