@yworks/optimizer
yFiles for HTML obfuscation and optimization tool
Last updated 12 days ago by yworks .
MIT · Original npm · Tarball · package.json
$ cnpm install @yworks/optimizer 
SYNC missed versions from official npm registry.

yFiles for HTML Optimizer

Use this tool to obfuscate and optimize your yFiles for HTML applications.

The optimizer will obfuscate the public API of the yFiles module files, as well as yFiles API usages in application sources.

Note that this tool is meant to be used in production builds. The resulting yFiles module files will be tailor-made to the yFiles API usages in the application sources that were processed along with the yFiles modules.

We highly recommend obfuscating the yFiles for HTML library prior to deploying your application to a public web server to reduce the download size of the library for the end user. Note that, at the time of writing, you are not required to use obfuscation.

Obfuscation Excludes

The optimizer might wrongly replace non-yFiles API calls if they have the same name as a member of the yFiles API. To avoid this, the optimizer comes with a list of common JavaScript API names that it should not change in any case. If the optimizer erroneously replaces non-yFiles calls in your code, there are two possibilities to prevent this:

  • Use scope-local @yjs:keep comments to exclude these members from obfuscation in a particular scope. This is the preferred approach, because the excluded names will still be obfuscated in yFiles modules and all other scopes.
    // @yjs:keep=install,apply
    function my() {
      // "install" and "apply" will not be obfuscated within this scope
      someAPI.install()
      someAPI.apply()
    }
    
    // @yjs:keep
    function my() {
      // No names will be obfuscated within this scope at all
      //...
    }
    
  • Add the member to the blacklist that can be passed as an option to the optimizer. This will prevent the passed names from being obfuscated in the yFiles modules and all application sources.

Options

  • blacklist An array of names that should never be renamed by the optimizer. See Obfuscation Excludes
  • loglevel One of "error", "warn", "info", "verbose", "debug", "silly". Default is "info".

Webpack Plugin

To use this optimizer as a webpack plugin, add the plugin the webpack config:

const OptimizerPlugin = require('@yworks/optimizer/webpack-plugin')

module.exports = {
  plugins: [
    new OptimizerPlugin({
      blacklist: ['install','apply'],
      logLevel: 'info',
      ignore: ['**/lib/external/**/*.js',/exclude[/\\].*\.js/]
    })
  ]
}

Webpack Plugin Options

Options supported by the webpack plugin in addition to the optimizer options explained above:

  • ignore An array of minimatch-glob patterns or regexps specifying files that should be ignored by the optimizer. Note that the path separators are not normalized for regexp matching, i.e., on windows, /\\ignoreme.js/ would match, but /\/ignoreme.js/ would not.

    This option can be used when some source files contain language features that are not supported by the optimizer (e.g. dynamic imports).

    Use this option to ignore only files that do not contain any yFiles code. If the ignored files contain yFiles code, this code will not work with the optimized library.

  • shouldOptimize An function that determines whether a particular webpack module should be optimized. The default shouldOptimize function will exclude all node_modules from optimization. Example:

new OptimizerPlugin({
  shouldOptimize(module) {
    return (
      /node-module-that-uses-yfiles/.test(module.resource) ||
      !/node_modules/.test(module.resource)
    )
  }
}),

API

const { optimize } = require('@yworks/optimizer')

// libModules: [{source: sourceOfYFilesModuleA}, ...]
// sourceFiles: [{source: appSourceA}, ...]

const optimized = optimize( libModules, 
                            sourceFiles, 
                            {
                              blacklist: [], 
                              logLevel: 'warn'
                            })
                            
// optimized: 
// {
//    libModules: [{ 
//                    source: sourceOfYFilesModuleA
//                    result: optimizedYFilesModuleA
//                 }, ...]
//    sourceFiles: [{ 
//                    source: appSourceA
//                    result: optimizedAppSourceA
//                 }, ...]
// }                            
                            

The optimized sources are attached to the same objects passed to the optimizer, so additional information (e.g. destination paths) on these objects is not lost.

Examples

Please see your yFiles for HTML package for example usages of the optimizer.

License

MIT © yWorks GmbH

Current Tags

  • 1.0.3                                ...           latest (12 days ago)

17 Versions

  • 1.0.3                                ...           12 days ago
  • 1.0.2                                ...           a month ago
  • 1.0.1                                ...           3 months ago
  • 1.0.0                                ...           4 months ago
  • 0.1.12                                ...           4 months ago
  • 0.1.11                                ...           4 months ago
  • 0.1.10                                ...           4 months ago
  • 0.1.9                                ...           4 months ago
  • 0.1.8                                ...           4 months ago
  • 0.1.7                                ...           4 months ago
  • 0.1.6                                ...           5 months ago
  • 0.1.5                                ...           5 months ago
  • 0.1.4                                ...           5 months ago
  • 0.1.3                                ...           5 months ago
  • 0.1.2                                ...           6 months ago
  • 0.1.1                                ...           6 months ago
  • 0.1.0                                ...           6 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 22
Last Day 0
Last Week 0
Last Month 18
Dependencies (5)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |