diff --git a/.gitignore b/.gitignore index 7a1537b..2d2b47d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea -node_modules +node_modules \ No newline at end of file diff --git a/.npmignore b/.npmignore index 91b69fa..810ecab 100644 --- a/.npmignore +++ b/.npmignore @@ -4,4 +4,6 @@ node_modules # build src .babelrc -test.js \ No newline at end of file +test.js +webpack.config.js +build/index.js \ No newline at end of file diff --git a/build/index.js b/build/index.js index 2e392a4..369be71 100644 --- a/build/index.js +++ b/build/index.js @@ -1,4 +1,84 @@ -'use strict'; +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["linkToFunc"] = factory(); + else + root["linkToFunc"] = factory(); +})(this, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + var argumentsToArray = function argumentsToArray(args) { var start = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; @@ -70,4 +150,7 @@ Replace.absPath = function (absPath, link) { exports['default'] = Replace; module.exports = exports['default']; -//# sourceMappingURL=index.js.map \ No newline at end of file + +/***/ }) +/******/ ]); +}); \ No newline at end of file diff --git a/build/index.js.map b/build/index.js.map deleted file mode 100644 index 4e6df87..0000000 --- a/build/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/index.js"],"names":["argumentsToArray","args","start","end","length","Array","prototype","slice","call","linkReplace","absPath","arguments","settingLink","settingArgs","match","_replaceLink","link","requireIndex","i","settingArg","test","Error","itemArg","setingArg","replace","linkObject","toString","toAbsPath","getLink","Replace","exports","module"],"mappings":";;AAAA,IAAMA,mBAAmB,SAAnBA,gBAAmB,CAAUC,IAAV,EAA8C;AAAA,MAA9BC,KAA8B,uEAAtB,CAAsB;AAAA,MAAnBC,GAAmB,uEAAbF,KAAKG,MAAQ;;AACrE,SAAOC,MAAMC,SAAN,CAAgBC,KAAhB,CAAsBC,IAAtB,CAA2BP,IAA3B,EAAiCC,KAAjC,EAAwCC,GAAxC,CAAP;AACD,CAFD;;AAIA,IAAMM,cAAc,SAAdA,WAAc,GAAY;AAC9B,MAAIC,UAAUC,UAAU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AAb,CAAP;AACD,GAFD;AAGA,MAAID,OAAJ,EAAa;AACXe,eAAWE,SAAX,GAAuB,YAAY;AACjC,kBAAUjB,OAAV,GAAoBK,aAAaf,iBAAiBW,SAAjB,CAAb,CAApB;AACD,KAFD;AAGD;AACDc,aAAWG,OAAX,GAAqB,YAAY;AAC/B,WAAOhB,WAAP;AACD,GAFD;AAGA,SAAOa,UAAP;AACD,CApDD;;AAsDA,IAAMI,UAAU,SAAVA,OAAU,CAAUb,IAAV,EAAgB;AAC9B,SAAOP,YAAY,KAAZ,EAAmBO,IAAnB,CAAP;AACD,CAFD;AAGAa,QAAQnB,OAAR,GAAkB,UAAUA,OAAV,EAAmBM,IAAnB,EAAyB;AACzC,SAAOP,YAAYC,OAAZ,EAAoBM,IAApB,CAAP;AACD,CAFD;;AAIAc,QAAQ,SAAR,IAAqBD,OAArB;AACAE,OAAOD,OAAP,GAAiBA,QAAQ,SAAR,CAAjB","file":"index.js","sourcesContent":["const argumentsToArray = function (args, start = 0, end = args.length) {\n return Array.prototype.slice.call(args, start, end);\n};\n\nconst linkReplace = function () {\n let absPath = arguments[0];\n let settingLink = arguments[1];\n let settingArgs = (settingLink.match(/(:.*?)(?=[\\/\\(]|$)|(\\(\\/:.*?)\\)/ig) || []);\n const _replaceLink = function (args) {\n let link = settingLink;\n\n /*check args*/\n (() => {\n let requireIndex = 0;\n for (let i = 0; i < settingArgs.length; i++) {\n let settingArg = settingArgs[i];\n if (settingArg) {\n if (!(/^\\(.*?\\)$/.test(settingArg))) {\n requireIndex++;\n }\n }\n }\n if (args.length < requireIndex) {\n throw new Error(`${link} URL Args Required`);\n }\n })()\n\n for (let i = 0; i < settingArgs.length; i++) {\n let itemArg = args[i];\n let setingArg = settingArgs[i];\n if (setingArg) {\n if (/^\\(.*?\\)$/.test(setingArg)) {\n link = link.replace(setingArg, itemArg ? `/${itemArg}` : '');\n } else {\n link = link.replace(setingArg, itemArg || setingArg);\n }\n }\n }\n return link;\n };\n\n let linkObject = function () {\n return _replaceLink(argumentsToArray(arguments));\n };\n linkObject.toString = function () {\n return _replaceLink(argumentsToArray(arguments));\n };\n if (absPath) {\n linkObject.toAbsPath = function () {\n return `${absPath}${_replaceLink(argumentsToArray(arguments))}`;\n };\n }\n linkObject.getLink = function () {\n return settingLink;\n };\n return linkObject;\n}\n\nconst Replace = function (link) {\n return linkReplace(false, link);\n};\nReplace.absPath = function (absPath, link) {\n return linkReplace(absPath,link)\n}\n\nexports['default'] = Replace;\nmodule.exports = exports['default'];"]} \ No newline at end of file diff --git a/build/index.min.js b/build/index.min.js new file mode 100644 index 0000000..b38a342 --- /dev/null +++ b/build/index.min.js @@ -0,0 +1 @@ +!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.linkToFunc=n():t.linkToFunc=n()}(this,function(){return function(t){function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var e={};return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=0)}([function(t,n,e){"use strict";var r=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.length;return Array.prototype.slice.call(t,n,e)},o=function(){var t=arguments[0],n=arguments[1],e=n.match(/(:.*?)(?=[\/\(]|$)|(\(\/:.*?)\)/gi)||[],o=function(t){var r=n;!function(){for(var n=0,o=0;o 0 ? (c.charAt(0).toUpperCase() + c.substring(1)) : c; + }).join(''); +})(package.name); + +var createConfig = function (config) { + var baseConfig = { + output: { + path: buildPath, + filename: '[name].js', + library: libraryName, + libraryTarget: "umd" + }, + module: { + rules: [ + { + test: /\.(js|jsx)$/, + include: [srcPath], + use: [{ + loader: 'babel-loader', + }] + }, + ], + } + }; + return _.assign({}, baseConfig, config); +} + +module.exports = [ + createConfig({ + entry: { + ['index']: path.resolve(srcPath, 'index.js') + }, + plugins: [ + new webpack.NoEmitOnErrorsPlugin(), + ], + }), + createConfig({ + entry: { + ['index.min']: path.resolve(srcPath, 'index.js') + }, + plugins: [ + new webpack.optimize.UglifyJsPlugin({ + comments: false, + }), + new webpack.NoEmitOnErrorsPlugin(), + ], + }) +] \ No newline at end of file