Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize "vivliostyle.min.js" built from TypeScript source #531

Closed
MurakamiShinyu opened this issue Jul 23, 2019 · 1 comment
Closed

Optimize "vivliostyle.min.js" built from TypeScript source #531

MurakamiShinyu opened this issue Jul 23, 2019 · 1 comment

Comments

@MurakamiShinyu
Copy link
Member

With the default settings of webpack.config.js, object property names (including class method names) are not mangled and long names remain.

This can be changed with the Mangle properties options in the webpack.config.js.

Proposed setting:

const TerserPlugin = require("terser-webpack-plugin");
...
module.exports = {
  ...
  optimization: {
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          mangle: {
            properties: {
              keep_quoted: true,
              regex: /^[a-z]{2,}[A-Z]\w*$/,
              reserved: [
                "docTitle",
                "getCurrentPageProgression",
                "getPageSizes",
                "isTOCVisible",
                "layoutStyle",
                "loadDocument",
                "loadPublication",
                "loadXML",
                "navigateToInternalUrl",
                "navigateToPage",
                "printTimings",
                "queryZoomFactor",
                "setOptions",
                "showTOC"
              ]
            }
          }
        }
      })
    ]
  }
};

In this setting, property names to be mangled are limited to camelCase names starting with at least two lowercase letters and contains at least one uppercase letter. Most such names can be mangled safely, but there are some camelCase property names that need to be accessed with that name, listed in the reserved array.

@MurakamiShinyu MurakamiShinyu added this to the JS-to-TS migration milestone Jul 23, 2019
MurakamiShinyu added a commit that referenced this issue Jul 23, 2019
@MurakamiShinyu
Copy link
Member Author

Done. Further improvements will be made later.

MurakamiShinyu added a commit to vivliostyle/vivliostyle-ui that referenced this issue Jul 23, 2019
This setting is to minify the bundled js file "build/js/main.js".

(related issue on the vivliostyle.js side: vivliostyle/vivliostyle.js#531 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant