@repodog/rollup-config 0.3.28 → 1.0.1-alpha.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/README.md +32 -6
- package/index.cjs +82 -0
- package/package.json +18 -10
- package/dependencies.js +0 -13
- package/index.js +0 -96
package/README.md
CHANGED
|
@@ -5,20 +5,46 @@ The RepoDog Rollup config.
|
|
|
5
5
|
[](https://badge.fury.io/js/%40repodog%2Frollup-config)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Install package
|
|
9
9
|
|
|
10
10
|
```shell
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
# terminal
|
|
12
|
+
npm install @repodog/rollup-config --save-dev
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Install dependencies
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
# terminal
|
|
19
|
+
npm install @rollup/plugin-babel @rollup/plugin-image @rollup/plugin-json @rollup/plugin-node-resolve @rollup/plugin-terser rollup rollup-plugin-analyzer rollup-plugin-copy rollup-plugin-sourcemaps --save-dev
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Rollup uses Babel for code transformations so you will also need to install [`@repodog/babel-config`](../babel-config/README.md) and its dependencies.**
|
|
23
|
+
|
|
24
|
+
## Use package
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
// package.json
|
|
28
|
+
{
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rollup -c ./rollup.config.cjs"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
16
34
|
|
|
17
35
|
```javascript
|
|
18
|
-
// rollup.config.
|
|
36
|
+
// rollup.config.cjs
|
|
19
37
|
const repodogConfig = require('@repodog/rollup-config');
|
|
20
38
|
|
|
21
39
|
module.exports = {
|
|
22
|
-
...repodogConfig,
|
|
40
|
+
...repodogConfig(),
|
|
23
41
|
};
|
|
24
42
|
```
|
|
43
|
+
|
|
44
|
+
### Environment variables
|
|
45
|
+
|
|
46
|
+
`NODE_ENV` = `''prod' || 'production' || 'dev' || 'development'`
|
|
47
|
+
|
|
48
|
+
When set to `''prod'` or `'production'`, terser mangles and compresses, the bundle analyser runs, and source maps are omitted.
|
|
49
|
+
|
|
50
|
+
**You cam also use the environment variables outlined in [`@repodog/babel-config`](../babel-config/README.md#environment-variables) to control what is output.**
|
package/index.cjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
const { babel } = require('@rollup/plugin-babel');
|
|
3
|
+
const image = require('@rollup/plugin-image');
|
|
4
|
+
const json = require('@rollup/plugin-json');
|
|
5
|
+
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
|
6
|
+
const terser = require('@rollup/plugin-terser');
|
|
7
|
+
const { existsSync, mkdirSync, writeFileSync } = require('node:fs');
|
|
8
|
+
const { basename } = require('node:path');
|
|
9
|
+
const { plugin: analyzer } = require('rollup-plugin-analyzer');
|
|
10
|
+
const copy = require('rollup-plugin-copy');
|
|
11
|
+
const sourcemaps = require('rollup-plugin-sourcemaps');
|
|
12
|
+
|
|
13
|
+
const { NODE_ENV } = process.env;
|
|
14
|
+
const isProductionEnvironment = NODE_ENV === 'production' || NODE_ENV === 'prod';
|
|
15
|
+
const packageDirectory = process.cwd();
|
|
16
|
+
const external = id => !id.startsWith('.') && !id.startsWith('/');
|
|
17
|
+
|
|
18
|
+
const sourcemapPathTransform = sourcePath => {
|
|
19
|
+
if (/node_modules/.test(sourcePath)) {
|
|
20
|
+
return sourcePath;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return sourcePath.replace('../../src', `../${basename(packageDirectory)}/src/`);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports = (config = {}) => {
|
|
27
|
+
const extensions = ['.mjs', '.cjs', '.js', '.jsx', '.json', '.ts', '.tsx'];
|
|
28
|
+
|
|
29
|
+
const plugins = [
|
|
30
|
+
nodeResolve({
|
|
31
|
+
extensions,
|
|
32
|
+
preferBuiltins: true,
|
|
33
|
+
}),
|
|
34
|
+
babel({
|
|
35
|
+
babelHelpers: 'runtime',
|
|
36
|
+
extensions,
|
|
37
|
+
rootMode: 'upward',
|
|
38
|
+
}),
|
|
39
|
+
json(),
|
|
40
|
+
image(),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
if (config.copy) {
|
|
44
|
+
plugins.push(copy(config.copy));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isProductionEnvironment) {
|
|
48
|
+
plugins.push(
|
|
49
|
+
terser(),
|
|
50
|
+
analyzer({
|
|
51
|
+
writeTo: analysis => {
|
|
52
|
+
if (!existsSync(`${packageDirectory}/dist`)) {
|
|
53
|
+
mkdirSync(`${packageDirectory}/dist`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
writeFileSync(`${packageDirectory}/dist/production.analysis.txt`, analysis);
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!isProductionEnvironment) {
|
|
63
|
+
plugins.push(sourcemaps());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
external,
|
|
68
|
+
input: `${packageDirectory}/src/index`,
|
|
69
|
+
onwarn: ({ code, message }) => {
|
|
70
|
+
if (code !== 'THIS_IS_UNDEFIEND') {
|
|
71
|
+
console.error(message); // eslint-disable-line no-console
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
output: {
|
|
75
|
+
file: `${packageDirectory}/dist/main/index.mjs`,
|
|
76
|
+
format: 'esm',
|
|
77
|
+
sourcemap: true,
|
|
78
|
+
sourcemapPathTransform,
|
|
79
|
+
},
|
|
80
|
+
plugins,
|
|
81
|
+
};
|
|
82
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repodog/rollup-config",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The RepoDog
|
|
5
|
-
"author": "Dylan Aubrey <dylanaubrey@gmail.com>",
|
|
6
|
-
"license": "MIT",
|
|
3
|
+
"version": "1.0.1-alpha.0",
|
|
4
|
+
"description": "The RepoDog Rollup config module.",
|
|
7
5
|
"homepage": "https://github.com/badbatch/repodog",
|
|
8
6
|
"bugs": {
|
|
9
7
|
"url": "https://github.com/badbatch/repodog/issues"
|
|
10
8
|
},
|
|
11
9
|
"repository": {
|
|
10
|
+
"directory": "packages/rollup-config",
|
|
12
11
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/badbatch/repodog"
|
|
12
|
+
"url": "https://github.com/badbatch/repodog/configs/rollup-config"
|
|
14
13
|
},
|
|
15
14
|
"publishConfig": {
|
|
16
15
|
"access": "public"
|
|
17
16
|
},
|
|
18
|
-
"main": "index.
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
"main": "index.cjs",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Dylan Aubrey",
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@rollup/plugin-babel": "< 7",
|
|
22
|
+
"@rollup/plugin-image": "< 4",
|
|
23
|
+
"@rollup/plugin-json": "< 7",
|
|
24
|
+
"@rollup/plugin-node-resolve": "< 16",
|
|
25
|
+
"@rollup/plugin-terser": "< 1",
|
|
26
|
+
"rollup": "< 4",
|
|
27
|
+
"rollup-plugin-analyzer": "< 5",
|
|
28
|
+
"rollup-plugin-copy": "< 4",
|
|
29
|
+
"rollup-plugin-sourcemaps": "< 1"
|
|
30
|
+
}
|
|
23
31
|
}
|
package/dependencies.js
DELETED
package/index.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const appRoot = require('app-root-path');
|
|
2
|
-
const { outputFileSync } = require('fs-extra');
|
|
3
|
-
const { basename, resolve } = require('path');
|
|
4
|
-
const { plugin: analyzer } = require('rollup-plugin-analyzer');
|
|
5
|
-
const babel = require('rollup-plugin-babel');
|
|
6
|
-
const commonjs = require('rollup-plugin-commonjs');
|
|
7
|
-
const json = require('rollup-plugin-json');
|
|
8
|
-
const nodeResolve = require('rollup-plugin-node-resolve');
|
|
9
|
-
const { terser } = require('rollup-plugin-terser');
|
|
10
|
-
|
|
11
|
-
const appRootPath = appRoot.toString();
|
|
12
|
-
let rootPackageJson;
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
16
|
-
rootPackageJson = require(resolve(appRootPath, 'package.json'));
|
|
17
|
-
} catch (error) {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.error(`No package.json found in in root directory ${appRootPath}`, error);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const packageDir = resolve(process.cwd());
|
|
23
|
-
let currentPackageJson;
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
27
|
-
currentPackageJson = require(`${packageDir}/package.json`);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.error(`No package.json found in directory ${packageDir}`, error);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const rootDevDependencies = Object.keys(rootPackageJson.devDependencies || {});
|
|
34
|
-
const devDependencies = Object.keys(currentPackageJson.devDependencies || {});
|
|
35
|
-
const peerDependencies = Object.keys(currentPackageJson.peerDependencies || {});
|
|
36
|
-
const dependencies = Object.keys(currentPackageJson.dependencies || {});
|
|
37
|
-
const externalModuleNames = [...rootDevDependencies, ...dependencies, ...peerDependencies, ...devDependencies];
|
|
38
|
-
|
|
39
|
-
function external(id) {
|
|
40
|
-
return externalModuleNames.some(name => id.startsWith(name));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const extensions = ['.mjs', '.js', '.jsx', 'json', '.ts', '.tsx'];
|
|
44
|
-
|
|
45
|
-
const defaultPlugins = [
|
|
46
|
-
nodeResolve({
|
|
47
|
-
extensions,
|
|
48
|
-
preferBuiltins: true,
|
|
49
|
-
}),
|
|
50
|
-
commonjs(),
|
|
51
|
-
json(),
|
|
52
|
-
babel({
|
|
53
|
-
babelHelpers: 'runtime',
|
|
54
|
-
configFile: `${appRootPath}/babel.config.js`,
|
|
55
|
-
extensions,
|
|
56
|
-
skipPreflightCheck: true,
|
|
57
|
-
}),
|
|
58
|
-
];
|
|
59
|
-
|
|
60
|
-
function sourcemapPathTransform(sourcePath) {
|
|
61
|
-
if (/node_modules/.test(sourcePath)) return sourcePath;
|
|
62
|
-
return sourcePath.replace('../../src/', `../${basename(packageDir)}/src/`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports =
|
|
66
|
-
process.env.NODE_ENV === 'development'
|
|
67
|
-
? {
|
|
68
|
-
external,
|
|
69
|
-
input: `${packageDir}/src/index`,
|
|
70
|
-
output: {
|
|
71
|
-
file: `${packageDir}/lib/browser/index.js`,
|
|
72
|
-
format: 'esm',
|
|
73
|
-
sourcemap: true,
|
|
74
|
-
sourcemapPathTransform,
|
|
75
|
-
},
|
|
76
|
-
plugins: [...defaultPlugins],
|
|
77
|
-
}
|
|
78
|
-
: {
|
|
79
|
-
external,
|
|
80
|
-
input: `${packageDir}/src/index`,
|
|
81
|
-
output: {
|
|
82
|
-
file: `${packageDir}/lib/browser/index.js`,
|
|
83
|
-
format: 'esm',
|
|
84
|
-
sourcemap: true,
|
|
85
|
-
sourcemapPathTransform,
|
|
86
|
-
},
|
|
87
|
-
plugins: [
|
|
88
|
-
...defaultPlugins,
|
|
89
|
-
terser(),
|
|
90
|
-
analyzer({
|
|
91
|
-
writeTo: analysisString => {
|
|
92
|
-
outputFileSync(`${packageDir}/lib/browser/production.analysis.txt`, analysisString);
|
|
93
|
-
},
|
|
94
|
-
}),
|
|
95
|
-
],
|
|
96
|
-
};
|