Skip to content

Commit cb00c63

Browse files
committed
Use rollup to build the code and generate CommonJS and UMD versions
1 parent 2699332 commit cb00c63

File tree

8 files changed

+294
-40
lines changed

8 files changed

+294
-40
lines changed

bin/build.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,12 @@ var build = () => {
3333
'utf8'
3434
)
3535

36-
// update slugify
37-
var source =
38-
fs.readFileSync(path.resolve(__dirname, '../slugify.js'), 'utf8')
39-
.replace(
40-
/var charMap = JSON\.parse\(.*\)/,
41-
`var charMap = JSON.parse('${JSON.stringify(sort(charmap)).replace(/'/g, '\\\'')}')`
42-
)
43-
.replace(
44-
/var locales = JSON\.parse\(.*\)/,
45-
`var locales = JSON.parse('${JSON.stringify(clean(locales))}')`
46-
)
47-
fs.writeFileSync(path.resolve(__dirname, '../slugify.js'), source, 'utf8')
36+
// update locales.json in src folder
37+
fs.writeFileSync(
38+
path.resolve(__dirname, '../src/locales.json'),
39+
JSON.stringify(clean(locales), null, 2),
40+
'utf8'
41+
)
4842
}
4943

5044
build()

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@
1818
"devDependencies": {
1919
"coveralls": "^3.1.0",
2020
"mocha": "^7.2.0",
21-
"nyc": "^15.1.0"
21+
"nyc": "^15.1.0",
22+
"rollup": "^1.32.1",
23+
"@rollup/plugin-json": "^4.1.0"
2224
},
23-
"main": "./slugify.js",
25+
"main": "./slugify.cjs.js",
26+
"module": "./slugify.mjs",
27+
"unpkg": "./slugify.js",
28+
"jsdelivr": "./slugify.js",
2429
"files": [
2530
"LICENSE",
2631
"README.md",
2732
"slugify.d.ts",
33+
"slugify.cjs.js",
34+
"slugify.mjs",
2835
"slugify.js"
2936
],
3037
"types": "slugify.d.ts",
3138
"scripts": {
32-
"build": "node bin/build",
39+
"build": "node bin/build && npx rollup -c",
3340
"test:ci": "npx mocha --recursive",
3441
"test:cov": "npx nyc --reporter=lcov --reporter=text-summary mocha -- --recursive",
3542
"test": "npm run build && npm run test:ci"

rollup.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pkg from './package.json';
2+
import json from '@rollup/plugin-json';
3+
4+
export default [
5+
{
6+
input: 'src/slugify.js',
7+
output: [
8+
{ file: pkg.main, format: 'cjs', exports: 'auto' },
9+
{ file: pkg.module, format: 'esm', exports: 'auto' },
10+
{ file: pkg.unpkg, format: 'umd', exports: 'auto', name: 'slugify' }
11+
],
12+
plugins: [
13+
json({
14+
compact: true,
15+
namedExports: false
16+
})
17+
]
18+
}
19+
];

slugify.cjs.js

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)