rollerwheel 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +0 -0
- package/package.json +31 -0
- package/roller.js +113 -0
package/.env
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rollerwheel",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "CLI tool for bundling client.js with Rollup",
|
|
5
|
+
"main": "roller.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"roller": "./roller.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"rollup",
|
|
11
|
+
"bundler",
|
|
12
|
+
"cli"
|
|
13
|
+
],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/core": "^7.26.7",
|
|
18
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.26.7",
|
|
19
|
+
"@babel/preset-env": "^7.26.7",
|
|
20
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
21
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
22
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
23
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
24
|
+
"rollup": "^4.0.0",
|
|
25
|
+
"rollup-plugin-ignore": "^1.0.10",
|
|
26
|
+
"rollup-plugin-polyfill-node": "^0.13.0"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=14.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/roller.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { log, warn } = console
|
|
4
|
+
|
|
5
|
+
const { rollup, watch } = require('rollup')
|
|
6
|
+
const commonjs = require('@rollup/plugin-commonjs')
|
|
7
|
+
const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
|
8
|
+
const nodePolyfills = require('rollup-plugin-polyfill-node')
|
|
9
|
+
const ignore = require('rollup-plugin-ignore')
|
|
10
|
+
const babel = require('@rollup/plugin-babel').babel
|
|
11
|
+
const { existsSync } = require('fs')
|
|
12
|
+
const { join, dirname } = require('path')
|
|
13
|
+
const json = require('@rollup/plugin-json')
|
|
14
|
+
|
|
15
|
+
// Parse command line args
|
|
16
|
+
const args = process.argv.slice(2)
|
|
17
|
+
const watchMode = args.includes('--watch') || args.includes('-w')
|
|
18
|
+
|
|
19
|
+
const main = async () => {
|
|
20
|
+
try {
|
|
21
|
+
const cwd = process.cwd()
|
|
22
|
+
const inputFile = join(cwd, 'client.js')
|
|
23
|
+
|
|
24
|
+
// Check if client.js exists
|
|
25
|
+
if (!existsSync(inputFile)) {
|
|
26
|
+
warn(`Error: client.js not found in ${cwd}`)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Determine output path
|
|
31
|
+
const staticDir = join(cwd, 'static')
|
|
32
|
+
const outputFile = existsSync(staticDir)
|
|
33
|
+
? join(staticDir, 'client.bundle.js')
|
|
34
|
+
: join(cwd, 'client.bundle.js')
|
|
35
|
+
|
|
36
|
+
const config = {
|
|
37
|
+
input: inputFile,
|
|
38
|
+
plugins: [
|
|
39
|
+
nodeResolve({
|
|
40
|
+
browser: true,
|
|
41
|
+
modulesOnly: false
|
|
42
|
+
}),
|
|
43
|
+
babel({
|
|
44
|
+
babelHelpers: 'bundled',
|
|
45
|
+
presets: [
|
|
46
|
+
[require.resolve('@babel/preset-env'), {
|
|
47
|
+
targets: '> 0.25%, not dead',
|
|
48
|
+
loose: true
|
|
49
|
+
}]
|
|
50
|
+
],
|
|
51
|
+
plugins: [
|
|
52
|
+
[require.resolve('@babel/plugin-proposal-pipeline-operator'), {
|
|
53
|
+
proposal: 'minimal'
|
|
54
|
+
}]
|
|
55
|
+
],
|
|
56
|
+
// Make sure Babel processes files from the project directory
|
|
57
|
+
exclude: 'node_modules/**',
|
|
58
|
+
babelrc: false,
|
|
59
|
+
configFile: false
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
ignore(['inspector']),
|
|
63
|
+
json(),
|
|
64
|
+
commonjs({
|
|
65
|
+
transformMixedEsModules: true,
|
|
66
|
+
requireReturnsDefault: 'auto'
|
|
67
|
+
}),
|
|
68
|
+
nodePolyfills()
|
|
69
|
+
],
|
|
70
|
+
output: {
|
|
71
|
+
file: outputFile,
|
|
72
|
+
format: 'iife',
|
|
73
|
+
sourcemap: 'inline'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (watchMode) {
|
|
78
|
+
log(`Watching ${inputFile} for changes...`)
|
|
79
|
+
|
|
80
|
+
const watcher = watch(config)
|
|
81
|
+
|
|
82
|
+
watcher.on('event', event => {
|
|
83
|
+
if (event.code === 'START') {
|
|
84
|
+
log('Building...')
|
|
85
|
+
} else if (event.code === 'BUNDLE_END') {
|
|
86
|
+
log(`✓ Bundle created at ${outputFile} (${event.duration}ms)`)
|
|
87
|
+
} else if (event.code === 'ERROR') {
|
|
88
|
+
warn(`Build error: ${event.error.message}`)
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// Handle Ctrl+C
|
|
93
|
+
process.on('SIGINT', () => {
|
|
94
|
+
log('\nStopping watcher...')
|
|
95
|
+
watcher.close()
|
|
96
|
+
process.exit(0)
|
|
97
|
+
})
|
|
98
|
+
} else {
|
|
99
|
+
log(`Bundling ${inputFile}...`)
|
|
100
|
+
|
|
101
|
+
const bundle = await rollup(config)
|
|
102
|
+
await bundle.write(config.output)
|
|
103
|
+
await bundle.close()
|
|
104
|
+
|
|
105
|
+
log(`✓ Bundle created at ${outputFile}`)
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
warn(`Build failed: ${error.message}`)
|
|
109
|
+
process.exit(1)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
main()
|