-
Notifications
You must be signed in to change notification settings - Fork 8
/
rollup.config.js
119 lines (103 loc) · 3.2 KB
/
rollup.config.js
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
108
109
110
111
112
113
114
115
116
117
118
119
import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
import autoPreprocess from 'svelte-preprocess';
import babel from 'rollup-plugin-babel';
const production = !process.env.ROLLUP_WATCH;
const name = pkg.name
.replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
.replace(/^\w/, m => m.toUpperCase())
.replace(/-\w/g, m => m[1].toUpperCase());
console.log(`is prod ${production}`, name);
/**
* amd – Asynchronous Module Definition, used with module loaders like RequireJS
* cjs – CommonJS, suitable for Node and other bundlers
* esm – Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a <script type=module> tag in modern browsers
* iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this.)
* umd – Universal Module Definition, works as amd, cjs and iife all in one
* system – Native format of the SystemJS loader
*/
const input = ((!production) ? 'src/main.js' : 'src/components/components.module.js');
const output = ((!production)
? {
sourcemap: true,
format: 'iife',
name: name,
file: 'public/jsecaptcha.iife.js',
//dir: 'public/'
}
: [
{ file: 'dist/jsecaptcha.amd.min.js', format: 'amd', name },
{ file: 'dist/jsecaptcha.es.min.mjs', format: 'es' },
{ file: 'dist/jsecaptcha.iife.min.js', format: 'iife', name },
{ file: 'dist/jsecaptcha.umd.min.js', format: 'umd', name },
{ file: 'dist/jsecaptcha.system.min.js', format: 'system', name },
]
);
/*
const outputUMD = ((!production)
? {
sourcemap: true,
format: 'iife',
name: name,
file: 'public/jsecaptcha.iife.js'
}
: [
{
file: 'dist/jsecaptcha.umd.min.js',
format: 'umd',
name,
esModule: false
},
]
);
export default [
{
input: input,
plugins: [terser()],
output: outputUMD
},
];*/
export default {
input,
output,
plugins: [
babel({
runtimeHelpers: true,
}),
svelte({
// enable run-time checks when not in production
dev: !production,
/**
* Auto preprocess supported languages with
* '<template>'/'external src files' support
**/
preprocess: autoPreprocess({
postcss: true,
scss: { includePaths: ['src', 'node_modules'] },
}),
customElement: production,
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration —
// consult the documentation for details:
// https://github.com/rollup/rollup-plugin-commonjs
resolve(),
commonjs({
include: ['node_modules/**'],
}),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};