-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrollup.config.mjs
107 lines (98 loc) · 2.49 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// import * as url from "url"
// import alias from "@rollup/plugin-alias"
import resolve from "@rollup/plugin-node-resolve"
// import { nodeResolve } from "@rollup/plugin-node-resolve";
import config from "./package.json" with { type: "json" }
import startCase from "lodash/startCase.js"
import camelCase from "lodash/camelCase.js"
import upperFirst from "lodash/upperFirst.js"
// const __dirname = url.fileURLToPath(new URL(".", import.meta.url))
const banner = `/*!\nMarksmith ${config.version}\n*/`
const commonOutput = {
name: "MarksmithController",
format: "es",
inlineDynamicImports: true,
globals: {
"@hotwired/stimulus": "Stimulus"
},
banner
}
const input = "app/frontend/entrypoints/javascript/controllers/export.js"
const plugins = [resolve()]
const configFor = (controllerName) => {
const fileName = `${controllerName}_controller`
const className = upperFirst(camelCase(startCase(fileName)))
const inputPath = `app/frontend/entrypoints/javascript/controllers/${fileName}.js`
const nonStimulusDeps = [
"@rails/activestorage",
"@rails/request.js",
"@github/markdown-toolbar-element",
"@github/paste-markdown"
]
const versions = {
full: {
external: []
},
"no-stimulus": {
external: [
"@hotwired/stimulus",
]
},
}
const finalConfig = []
Object.keys(versions).forEach((name) => {
const payload = versions[name]
const outputPath = `app/assets/javascripts/${fileName}-${name}.esm.js`
const config = {
input: inputPath,
output: {
...commonOutput,
file: outputPath,
format: "iife",
name: className,
globals: {
// Avo knows to expose the Stimulus Controller to the global window object using the FakeStimulus object.
"@hotwired/stimulus": "FakeStimulus"
}
},
plugins,
external: payload.external,
}
finalConfig.push(config)
})
return finalConfig
}
const avoExports = [
...configFor("marksmith"),
...configFor("list_continuation")
]
export default [
{
input,
output: [
{
file: "dist/marksmith-core.esm.js",
...commonOutput
}
],
plugins,
external: [
"@hotwired/stimulus",
"@rails/activestorage",
"@rails/request.js",
"@github/markdown-toolbar-element",
"@github/paste-markdown"
],
},
{
input,
output: [
{
file: "dist/marksmith.esm.js",
...commonOutput
}
],
plugins,
},
...avoExports
]