Browse Source

Add CJS build fallback

pull/979/head
Vitaly Puzrin 5 months ago
parent
commit
7f0f211a20
  1. 10
      package.json
  2. 41
      support/rollup.config.mjs
  3. 10
      test/cjs.js

10
package.json

@ -11,12 +11,12 @@
],
"repository": "markdown-it/markdown-it",
"license": "MIT",
"main": "dist/markdown-it.js",
"main": "dist/markdown-it.cjs.js",
"module": "index.mjs",
"exports": {
".": {
"import": "./index.mjs",
"require": "./dist/markdown-it.js"
"require": "./dist/markdown-it.cjs.js"
},
"./*": {
"require": "./*",
@ -28,16 +28,16 @@
},
"scripts": {
"lint": "eslint --ext js --ext mjs .",
"test": "npm run lint && c8 -r text -r html -r lcov mocha && node support/specsplit.mjs",
"test": "npm run lint && CJS_ONLY=1 npm run build && c8 --exclude dist --exclude test -r text -r html -r lcov mocha && node support/specsplit.mjs",
"doc": "node support/build_doc.mjs",
"gh-doc": "npm run doc && gh-pages -d apidoc -f",
"demo": "npm run lint && node support/build_demo.mjs",
"gh-demo": "npm run demo && gh-pages -d demo -f -b master -r git@github.com:markdown-it/markdown-it.github.io.git",
"build": "npm run lint && rollup -c support/rollup.config.mjs",
"build": "rollup -c support/rollup.config.mjs",
"benchmark-deps": "npm install --prefix benchmark/extra/ -g marked@0.3.6 commonmark@0.26.0 markdown-it/markdown-it.git#2.2.1",
"specsplit": "support/specsplit.mjs good -o test/fixtures/commonmark/good.txt && support/specsplit.mjs bad -o test/fixtures/commonmark/bad.txt && support/specsplit.mjs",
"todo": "grep 'TODO' -n -r ./lib 2>/dev/null",
"prepublishOnly": "npm run build && npm run gh-demo && npm run gh-doc"
"prepublishOnly": "npm test && npm run build && npm run gh-demo && npm run gh-doc"
},
"files": [
"index.mjs",

41
support/rollup.config.mjs

@ -1,12 +1,11 @@
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import { babel } from '@rollup/plugin-babel'
import { readFileSync } from 'fs'
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)))
export default {
const config_umd_full = {
input: 'index.mjs',
output: [
{
@ -18,12 +17,7 @@ export default {
terser({
mangle: false,
compress: false,
format: {
comments: 'all',
beautify: true,
ascii_only: true,
indent_level: 2
}
format: { comments: 'all', beautify: true, ascii_only: true, indent_level: 2 }
})
]
},
@ -33,16 +27,13 @@ export default {
name: 'markdownit',
plugins: [
terser({
format: {
ascii_only: true
}
format: { ascii_only: true }
})
]
}
],
plugins: [
nodeResolve({ preferBuiltins: true }),
commonjs(),
resolve(),
babel({ babelHelpers: 'bundled' }),
{
banner () {
@ -51,3 +42,25 @@ export default {
}
]
}
const config_cjs_no_deps = {
input: 'index.mjs',
output: {
file: 'dist/markdown-it.cjs.js',
format: 'cjs'
},
external: Object.keys(pkg.dependencies),
plugins: [
resolve(),
babel({ babelHelpers: 'bundled' })
]
}
let config = [
config_umd_full,
config_cjs_no_deps
]
if (process.env.CJS_ONLY) config = [config_cjs_no_deps]
export default config

10
test/cjs.js

@ -0,0 +1,10 @@
'use strict'
const assert = require('assert')
const md = require('../')()
describe('CJS', () => {
it('require', () => {
assert.strictEqual(md.render('abc'), '<p>abc</p>\n')
})
})
Loading…
Cancel
Save