@repodog/rollup-config 1.1.5 → 1.1.7
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 +4 -0
- package/index.cjs +13 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,10 @@ module.exports = {
|
|
|
43
43
|
|
|
44
44
|
### Environment variables
|
|
45
45
|
|
|
46
|
+
`MODULE_SYSTEM` = `'esm' || 'cjs'`
|
|
47
|
+
|
|
48
|
+
Sets `output.format`, directory name within `./dist` output, and the extension of the bundled output file. Default `'esm'`.
|
|
49
|
+
|
|
46
50
|
`NODE_ENV` = `'prod' || 'production' || 'dev' || 'development'`
|
|
47
51
|
|
|
48
52
|
When set to `'prod'` or `'production'`, terser mangles and compresses, the bundle analyser runs, and source maps are omitted.
|
package/index.cjs
CHANGED
|
@@ -10,17 +10,18 @@ const { plugin: analyzer } = require('rollup-plugin-analyzer');
|
|
|
10
10
|
const copy = require('rollup-plugin-copy');
|
|
11
11
|
const sourcemaps = require('rollup-plugin-sourcemaps');
|
|
12
12
|
|
|
13
|
-
const { NODE_ENV } = process.env;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const { MODULE_SYSTEM = 'esm', NODE_ENV } = process.env;
|
|
14
|
+
const isProdEnv = NODE_ENV === 'production' || NODE_ENV === 'prod';
|
|
15
|
+
const packageDir = process.cwd();
|
|
16
16
|
const external = id => !id.startsWith('.') && !id.startsWith('/');
|
|
17
|
+
const outputExtension = MODULE_SYSTEM === 'esm' ? 'mjs' : 'cjs';
|
|
17
18
|
|
|
18
19
|
const sourcemapPathTransform = sourcePath => {
|
|
19
20
|
if (/node_modules/.test(sourcePath)) {
|
|
20
21
|
return sourcePath;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
return sourcePath.replace('../../src', `../${basename(
|
|
24
|
+
return sourcePath.replace('../../src', `../${basename(packageDir)}/src/`);
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
module.exports = (config = {}) => {
|
|
@@ -44,36 +45,36 @@ module.exports = (config = {}) => {
|
|
|
44
45
|
plugins.push(copy(config.copy));
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
if (
|
|
48
|
+
if (isProdEnv) {
|
|
48
49
|
plugins.push(
|
|
49
50
|
terser(),
|
|
50
51
|
analyzer({
|
|
51
52
|
writeTo: analysis => {
|
|
52
|
-
if (!existsSync(`${
|
|
53
|
-
mkdirSync(`${
|
|
53
|
+
if (!existsSync(`${packageDir}/dist`)) {
|
|
54
|
+
mkdirSync(`${packageDir}/dist`);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
writeFileSync(`${
|
|
57
|
+
writeFileSync(`${packageDir}/dist/production.analysis.txt`, analysis);
|
|
57
58
|
},
|
|
58
59
|
})
|
|
59
60
|
);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
if (!
|
|
63
|
+
if (!isProdEnv) {
|
|
63
64
|
plugins.push(sourcemaps());
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
return {
|
|
67
68
|
external,
|
|
68
|
-
input: `${
|
|
69
|
+
input: `${packageDir}/src/index`,
|
|
69
70
|
onwarn: ({ code, message }) => {
|
|
70
71
|
if (code !== 'THIS_IS_UNDEFIEND') {
|
|
71
72
|
console.error(message); // eslint-disable-line no-console
|
|
72
73
|
}
|
|
73
74
|
},
|
|
74
75
|
output: {
|
|
75
|
-
file: `${
|
|
76
|
-
format:
|
|
76
|
+
file: `${packageDir}/dist/${MODULE_SYSTEM}/index.${outputExtension}`,
|
|
77
|
+
format: MODULE_SYSTEM,
|
|
77
78
|
sourcemap: true,
|
|
78
79
|
sourcemapPathTransform,
|
|
79
80
|
},
|