|
| 1 | +# obfuscator-loader for webpack |
| 2 | + |
| 3 | +This is a module loader for webpack wich obfuscate module source code using [javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator). |
| 4 | + |
| 5 | +## installation |
| 6 | +```npm install --save-dev obfuscator-loader``` |
| 7 | + |
| 8 | +## Why not a plugin? |
| 9 | +Obfuscating code can results in quite large files. It's a good idea to obfuscate only your code leaving third party libraries unobfuscated. |
| 10 | +This is simple to achieve using a plugin if you plan to split your code and third party code in different bundles. Take a look at [this plugin](https://github.com/javascript-obfuscator/webpack-obfuscator). |
| 11 | + |
| 12 | + |
| 13 | +Sometimes you need to output a single js bundle but you still need to obfuscate the source code of some particular module. In these cases a loader can do the trick. |
| 14 | +For example I happened to had to bundle a big third party library (not a module of any sort, I had to use [script-loader](https://github.com/webpack-contrib/script-loader)) in one of my project and I was requested to obfuscate my code. |
| 15 | + |
| 16 | +## Usage |
| 17 | +Define a rule in your webpack config and use the obfuscator-loader as the last of your loaders for your modules. You can add the **enforce: 'post'** flag to ensure the loader will be called after normal loaders: |
| 18 | + |
| 19 | +```javascript |
| 20 | +module.exports = { |
| 21 | + module: { |
| 22 | + rules: [ |
| 23 | + { |
| 24 | + test: /\.js$/, |
| 25 | + exclude: [ path.resolve(__dirname, "justMySources") ], |
| 26 | + enforce: 'post', |
| 27 | + use: { loader: 'obfuscator-loader', options: obfuscatorOptions } |
| 28 | + }, |
| 29 | + ] |
| 30 | + } |
| 31 | +}; |
| 32 | +``` |
| 33 | + |
| 34 | +## Options |
| 35 | +This loader accepts the same options object of [javascript-loader](https://www.npmjs.com/package/javascript-obfuscator#options) |
| 36 | + |
| 37 | +## Limitations |
| 38 | +javascript-obfuscator option 'stringArray' is forced to false because if true dynamical requirements get added to code causing webpack to fail resolving some modules and emit CriticalDependenciesWarning warnings. |
| 39 | + |
| 40 | +## License |
| 41 | +``` |
| 42 | +MIT License |
| 43 | +
|
| 44 | +Copyright (c) 2018 Valerio Bianchi |
| 45 | +
|
| 46 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 47 | +of this software and associated documentation files (the "Software"), to deal |
| 48 | +in the Software without restriction, including without limitation the rights |
| 49 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 50 | +copies of the Software, and to permit persons to whom the Software is |
| 51 | +furnished to do so, subject to the following conditions: |
| 52 | +
|
| 53 | +The above copyright notice and this permission notice shall be included in all |
| 54 | +copies or substantial portions of the Software. |
| 55 | +
|
| 56 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 57 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 58 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 59 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 60 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 61 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 62 | +SOFTWARE. |
| 63 | +``` |
0 commit comments