@vitus-labs/tools-rollup 0.35.0 → 0.37.0
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/package.json +9 -9
- package/src/config/baseConfig.js +1 -1
- package/src/config/rollup.js +12 -11
- package/src/scripts/utils.js +58 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/tools-rollup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.com>",
|
|
6
6
|
"maintainers": [
|
|
@@ -19,22 +19,22 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@rollup/plugin-
|
|
23
|
-
"@rollup/plugin-
|
|
22
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
23
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
24
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
25
|
+
"@rollup/plugin-terser": "^0.3.0",
|
|
24
26
|
"@types/node": "^18.11.18",
|
|
25
27
|
"@zerollup/ts-transform-paths": "^1.7.18",
|
|
26
28
|
"chalk": "^4.1.2",
|
|
27
29
|
"find-up": "^5.0.0",
|
|
28
30
|
"lodash.merge": "^4.6.2",
|
|
29
31
|
"rimraf": "^3.0.2",
|
|
30
|
-
"rollup": "^
|
|
31
|
-
"rollup-plugin-
|
|
32
|
-
"rollup-plugin-dts": "^4.2.1",
|
|
32
|
+
"rollup": "^3.9.1",
|
|
33
|
+
"rollup-plugin-dts": "^5.1.1",
|
|
33
34
|
"rollup-plugin-filesize": "^9.1.2",
|
|
34
|
-
"rollup-plugin-
|
|
35
|
-
"rollup-plugin-typescript2": "^0.31.2",
|
|
35
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
36
36
|
"rollup-plugin-visualizer": "^5.9.0",
|
|
37
37
|
"ttypescript": "^1.5.15"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "63ab7e746b45524744d135201697e18f4c4c2bcb"
|
|
40
40
|
}
|
package/src/config/baseConfig.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = {
|
|
|
10
10
|
outputDir: 'analysis',
|
|
11
11
|
},
|
|
12
12
|
filesize: true,
|
|
13
|
-
extensions: ['.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
|
|
13
|
+
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
|
|
14
14
|
include: ['src'],
|
|
15
15
|
exclude: [
|
|
16
16
|
'lib',
|
package/src/config/rollup.js
CHANGED
|
@@ -4,8 +4,8 @@ const { nodeResolve } = require('@rollup/plugin-node-resolve')
|
|
|
4
4
|
const filesize = require('rollup-plugin-filesize')
|
|
5
5
|
const { visualizer } = require('rollup-plugin-visualizer')
|
|
6
6
|
const replace = require('@rollup/plugin-replace')
|
|
7
|
-
const { terser } = require('rollup
|
|
8
|
-
const babel = require('rollup
|
|
7
|
+
const { terser } = require('@rollup/plugin-terser')
|
|
8
|
+
const babel = require('@rollup/plugin-babel')
|
|
9
9
|
const dts = require('rollup-plugin-dts').default
|
|
10
10
|
const baseConfig = require('./baseConfig')
|
|
11
11
|
const { PKG, loadConfig, swapGlobals } = require('../utils')
|
|
@@ -15,7 +15,7 @@ const CONFIG = loadConfig(baseConfig)
|
|
|
15
15
|
const defineExtensions = (platform) => {
|
|
16
16
|
const platformExtensions = []
|
|
17
17
|
|
|
18
|
-
if (['browser', '
|
|
18
|
+
if (['browser', 'node', 'web', 'native'].includes(platform)) {
|
|
19
19
|
CONFIG.extensions.forEach((item) => {
|
|
20
20
|
platformExtensions.push(`.${platform}${item}`)
|
|
21
21
|
})
|
|
@@ -24,13 +24,14 @@ const defineExtensions = (platform) => {
|
|
|
24
24
|
return platformExtensions.concat(CONFIG.extensions)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const loadPlugins = ({ env, platform,
|
|
27
|
+
const loadPlugins = ({ env, platform, types, file }) => {
|
|
28
28
|
const extensions = defineExtensions(platform)
|
|
29
29
|
|
|
30
30
|
const babelConfig = {
|
|
31
31
|
extensions,
|
|
32
32
|
include: [CONFIG.sourceDir],
|
|
33
33
|
exclude: CONFIG.exclude,
|
|
34
|
+
babelHelpers: 'runtime',
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const tsConfig = {
|
|
@@ -53,8 +54,8 @@ const loadPlugins = ({ env, platform, typings, file }) => {
|
|
|
53
54
|
},
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
if (
|
|
57
|
-
tsConfig.tsconfigDefaults.compilerOptions.declaration =
|
|
57
|
+
if (types) {
|
|
58
|
+
tsConfig.tsconfigDefaults.compilerOptions.declaration = types
|
|
58
59
|
tsConfig.tsconfigDefaults.compilerOptions.declarationDir = CONFIG.typesDir
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -67,9 +68,9 @@ const loadPlugins = ({ env, platform, typings, file }) => {
|
|
|
67
68
|
if (CONFIG.replaceGlobals) {
|
|
68
69
|
const replaceOptions = {
|
|
69
70
|
__VERSION__: JSON.stringify(PKG.version),
|
|
70
|
-
|
|
71
|
+
__NODE__: JSON.stringify(platform === 'node'),
|
|
71
72
|
__WEB__: JSON.stringify(
|
|
72
|
-
['
|
|
73
|
+
['node', 'browser', 'universal'].includes(platform)
|
|
73
74
|
),
|
|
74
75
|
__BROWSER__: JSON.stringify(platform === 'browser'),
|
|
75
76
|
__NATIVE__: JSON.stringify(platform === 'native'),
|
|
@@ -119,8 +120,8 @@ const typescriptConfig = () => ({
|
|
|
119
120
|
plugins: [dts()],
|
|
120
121
|
})
|
|
121
122
|
|
|
122
|
-
const rollupConfig = ({ file, format, env,
|
|
123
|
-
const plugins = loadPlugins({ file, env,
|
|
123
|
+
const rollupConfig = ({ file, format, env, types, platform }) => {
|
|
124
|
+
const plugins = loadPlugins({ file, env, types, platform })
|
|
124
125
|
|
|
125
126
|
const buildOutput = {
|
|
126
127
|
input: CONFIG.sourceDir,
|
|
@@ -136,7 +137,7 @@ const rollupConfig = ({ file, format, env, typings, platform }) => {
|
|
|
136
137
|
plugins,
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
if (
|
|
140
|
+
if (types) {
|
|
140
141
|
return [buildOutput, typescriptConfig()]
|
|
141
142
|
}
|
|
142
143
|
|
package/src/scripts/utils.js
CHANGED
|
@@ -34,8 +34,63 @@ const BASE_VARIANTS = {
|
|
|
34
34
|
unpkg: { format: 'umd', env: 'production' },
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
const getExportsOptions = () => {
|
|
38
|
+
const exportsOptions = PKG['exports']
|
|
39
|
+
|
|
40
|
+
if (!exportsOptions) return []
|
|
41
|
+
|
|
42
|
+
if (typeof exportsOptions === 'string') {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
file: PKG['exports'],
|
|
46
|
+
...BASE_VARIANTS['module'],
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof exportsOptions === 'object') {
|
|
52
|
+
const result = []
|
|
53
|
+
|
|
54
|
+
if (exportsOptions.import) {
|
|
55
|
+
result.push({
|
|
56
|
+
file: exportsOptions.import,
|
|
57
|
+
...BASE_VARIANTS['module'],
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (exportsOptions.require) {
|
|
62
|
+
result.push({
|
|
63
|
+
file: exportsOptions.require,
|
|
64
|
+
...BASE_VARIANTS['main'],
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (exportsOptions.node) {
|
|
69
|
+
result.push({
|
|
70
|
+
file: exportsOptions.node,
|
|
71
|
+
...BASE_VARIANTS['module'],
|
|
72
|
+
platform: 'node',
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (exportsOptions.default) {
|
|
77
|
+
result.push({
|
|
78
|
+
file: exportsOptions.default,
|
|
79
|
+
...BASE_VARIANTS['module'],
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return []
|
|
87
|
+
}
|
|
88
|
+
|
|
37
89
|
const createBasicBuildVariants = () => {
|
|
38
|
-
const
|
|
90
|
+
const isModule = PKG['type'] === 'module'
|
|
91
|
+
let result = []
|
|
92
|
+
|
|
93
|
+
if (isModule) result = [...getExportsOptions()]
|
|
39
94
|
|
|
40
95
|
Object.keys(BASE_VARIANTS).forEach((key) => {
|
|
41
96
|
const PKGOutDir = PKG[key]
|
|
@@ -54,9 +109,9 @@ const createBasicBuildVariants = () => {
|
|
|
54
109
|
add()
|
|
55
110
|
}
|
|
56
111
|
} else if (hasBrowserBuild) {
|
|
57
|
-
// if has a different browser build, set default platform to
|
|
112
|
+
// if has a different browser build, set default platform to node
|
|
58
113
|
// as there is going to be created a separate browser build as well
|
|
59
|
-
add({ platform: '
|
|
114
|
+
add({ platform: 'node' })
|
|
60
115
|
} else {
|
|
61
116
|
add()
|
|
62
117
|
}
|