From f628ca142bc3fecc46167ede05d4faf2cb9ef69a Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Wed, 31 Oct 2018 11:37:54 +0900 Subject: [PATCH] Generate ECMAScript module for contrib (#1624) * Create separate entry point of copy-tex for webpack * Update katex.webpack.js comment * Generate ECMAScript for contrib * Update dependencies * Comment out documentations --- contrib/copy-tex/README.md | 6 ++++++ contrib/copy-tex/copy-tex.js | 1 - contrib/copy-tex/copy-tex.webpack.js | 6 ++++++ contrib/mathtex-script-type/README.md | 8 ++++++-- docs/autorender.md | 13 +++++++++++++ katex.webpack.js | 5 +++-- package.json | 1 + rollup.config.js | 15 +++++++++++---- webpack.common.js | 2 +- yarn.lock | 7 +++++++ 10 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 contrib/copy-tex/copy-tex.webpack.js diff --git a/contrib/copy-tex/README.md b/contrib/copy-tex/README.md index 4e63c68a..8c96a2a3 100644 --- a/contrib/copy-tex/README.md +++ b/contrib/copy-tex/README.md @@ -35,6 +35,12 @@ If you want to build your own custom copy handler based on this one, copy the `copy-tex.js` into your codebase and replace the `require` statement with `require('katex/contrib/copy-tex/katex2tex.js')`. + + ### Known Issues This extension has been tested on Chrome, Firefox, Edge, and Safari. diff --git a/contrib/copy-tex/copy-tex.js b/contrib/copy-tex/copy-tex.js index 78a54b20..ca6e08ac 100644 --- a/contrib/copy-tex/copy-tex.js +++ b/contrib/copy-tex/copy-tex.js @@ -1,4 +1,3 @@ -import './copy-tex.css'; import katexReplaceWithTex from './katex2tex'; // Global copy handler to modify behavior on .katex elements. diff --git a/contrib/copy-tex/copy-tex.webpack.js b/contrib/copy-tex/copy-tex.webpack.js new file mode 100644 index 00000000..9842a9e1 --- /dev/null +++ b/contrib/copy-tex/copy-tex.webpack.js @@ -0,0 +1,6 @@ +/** + * This is the webpack entry point for KaTeX. As ECMAScript doesn't support + * CSS modules natively, a separate entry point is used. + */ +import './copy-tex.css'; +import './copy-tex.js'; diff --git a/contrib/mathtex-script-type/README.md b/contrib/mathtex-script-type/README.md index 22fb4cd5..8836f94a 100644 --- a/contrib/mathtex-script-type/README.md +++ b/contrib/mathtex-script-type/README.md @@ -14,8 +14,6 @@ This extension should be loaded *after* all `script type=math/tex` blocks that y ```html ``` -Note that if the URL above contains `...` in-place of a version string, then this script has not yet -been deployed to the CDN. You can download the script and use it locally, or from a local KaTeX installation instead. For example, in the following simple page, we first load KaTeX as usual. @@ -34,3 +32,9 @@ After we're done writing `math/tex` scripts, we load this extension. ``` + + diff --git a/docs/autorender.md b/docs/autorender.md index 077e63ce..2f530c83 100644 --- a/docs/autorender.md +++ b/docs/autorender.md @@ -43,6 +43,19 @@ For example: ``` + + ## API This extension exposes a single function, `window.renderMathInElement`, with the following API: diff --git a/katex.webpack.js b/katex.webpack.js index c6c4df74..72327594 100644 --- a/katex.webpack.js +++ b/katex.webpack.js @@ -1,6 +1,7 @@ /** - * This is the webpack entry point for KaTeX. As flow[1] and jest[2] doesn't support - * CSS modules natively, a separate entry point is used and it is not flowtyped. + * This is the webpack entry point for KaTeX. As ECMAScript, flow[1] and jest[2] + * doesn't support CSS modules natively, a separate entry point is used and + * it is not flowtyped. * * [1] https://gist.github.com/lambdahands/d19e0da96285b749f0ef * [2] https://facebook.github.io/jest/docs/en/webpack.html diff --git a/package.json b/package.json index 9ed3c3a6..013acbc1 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "query-string": "^6.2.0", "rimraf": "^2.6.2", "rollup": "^0.66.0", + "rollup-plugin-alias": "^1.4.0", "rollup-plugin-babel": "^4.0.2", "selenium-webdriver": "^3.6.0", "sri-toolbox": "^0.2.0", diff --git a/rollup.config.js b/rollup.config.js index c09d395d..f6e957c5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,14 +1,21 @@ import babel from 'rollup-plugin-babel'; +import alias from 'rollup-plugin-alias'; + +const {targets} = require('./webpack.common'); process.env.NODE_ENV = 'esm'; -export default { - input: 'katex.js', +export default targets.map(({name, entry}) => ({ + input: entry.replace('.webpack', ''), output: { - file: 'dist/katex.mjs', + file: `dist/${name}.mjs`, format: 'es', }, plugins: [ babel({runtimeHelpers: true}), + alias({ + katex: '../katex.mjs', + }), ], -}; + external: '../katex.mjs', +})); diff --git a/webpack.common.js b/webpack.common.js index 3815bc68..8e3d3a04 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -27,7 +27,7 @@ const targets /*: Array */ = [ }, { name: 'contrib/copy-tex', - entry: './contrib/copy-tex/copy-tex.js', + entry: './contrib/copy-tex/copy-tex.webpack.js', }, { name: 'contrib/mathtex-script-type', diff --git a/yarn.lock b/yarn.lock index 83941aac..74763f79 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7917,6 +7917,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" +rollup-plugin-alias@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-alias/-/rollup-plugin-alias-1.4.0.tgz#120cba7c46621c03138f0ca6fd5dd2ade9872db9" + integrity sha512-lB094zdi19FS+1bVarVp9kBN0Zk41PdTGoCk0z8xesKO7RGjOo18cp1hUzEqrOQ4bM9+KLD9nbnu/XUxQm9pbg== + dependencies: + slash "^1.0.0" + rollup-plugin-babel@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.0.2.tgz#c073eeb0cc246324e6f6feaedbb90093841a138c"