Skip to content

Commit

Permalink
Use rollup to build the code and generate CommonJS and UMD versions
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Jan 18, 2025
1 parent 2699332 commit cb00c63
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 40 deletions.
18 changes: 6 additions & 12 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@ var build = () => {
'utf8'
)

// update slugify
var source =
fs.readFileSync(path.resolve(__dirname, '../slugify.js'), 'utf8')
.replace(
/var charMap = JSON\.parse\(.*\)/,
`var charMap = JSON.parse('${JSON.stringify(sort(charmap)).replace(/'/g, '\\\'')}')`
)
.replace(
/var locales = JSON\.parse\(.*\)/,
`var locales = JSON.parse('${JSON.stringify(clean(locales))}')`
)
fs.writeFileSync(path.resolve(__dirname, '../slugify.js'), source, 'utf8')
// update locales.json in src folder
fs.writeFileSync(
path.resolve(__dirname, '../src/locales.json'),
JSON.stringify(clean(locales), null, 2),
'utf8'
)
}

build()
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@
"devDependencies": {
"coveralls": "^3.1.0",
"mocha": "^7.2.0",
"nyc": "^15.1.0"
"nyc": "^15.1.0",
"rollup": "^1.32.1",
"@rollup/plugin-json": "^4.1.0"
},
"main": "./slugify.js",
"main": "./slugify.cjs.js",
"module": "./slugify.mjs",
"unpkg": "./slugify.js",
"jsdelivr": "./slugify.js",
"files": [
"LICENSE",
"README.md",
"slugify.d.ts",
"slugify.cjs.js",
"slugify.mjs",
"slugify.js"
],
"types": "slugify.d.ts",
"scripts": {
"build": "node bin/build",
"build": "node bin/build && npx rollup -c",
"test:ci": "npx mocha --recursive",
"test:cov": "npx nyc --reporter=lcov --reporter=text-summary mocha -- --recursive",
"test": "npm run build && npm run test:ci"
Expand Down
19 changes: 19 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pkg from './package.json';
import json from '@rollup/plugin-json';

export default [
{
input: 'src/slugify.js',
output: [
{ file: pkg.main, format: 'cjs', exports: 'auto' },
{ file: pkg.module, format: 'esm', exports: 'auto' },
{ file: pkg.unpkg, format: 'umd', exports: 'auto', name: 'slugify' }
],
plugins: [
json({
compact: true,
namedExports: false
})
]
}
];
53 changes: 53 additions & 0 deletions slugify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cb00c63

Please sign in to comment.