-
Notifications
You must be signed in to change notification settings - Fork 158
/
rollup.config.js
66 lines (63 loc) · 1.99 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
import typescript from '@rollup/plugin-typescript';
import copy from 'rollup-plugin-copy';
export default {
input: 'src/index.ts',
external: ['react'],
output: [
{
dir: 'dist',
format: 'es',
// This disables the warning "Mixing named and default exports"
exports: 'named',
/**
* This is required to prevent the error:
*
* Can't import the named export 'useContext' from non EcmaScript
* module (only default export is available)
*
* This error occurred in a Webpack 4 app (Create React App). We can
* hopefully remove the `interop` key if React decides to publish an
* ES module and/or Webpack 4 usage declines.
*
* -----
*
* Here is the Rollup documentation on `defaultOnly`:
*
* Named imports are forbidden. If such an import is encountered,
* Rollup throws an error even in es and system formats. That way it
* is ensures that the es version of the code is able to import
* non-builtin CommonJS modules in Node correctly.
*/
interop: 'defaultOnly',
/**
* This is required to prevent the error:
*
* TypeError: createContext only works in Client Components.
* Add the "use client" directive at the top of the file to use it.
*
* -----
*
* Here is the Rollup documentation on `banner`:
* A string to prepend/append to the bundle. You can also
* supply a function that returns a Promise that resolves
* to a string to generate it asynchronously
*
* (Note: banner and footer options will not
* break sourcemaps).
*/
banner: "'use client';",
},
{
file: 'dist/index.cjs',
format: 'cjs',
exports: 'named',
banner: "'use client';",
},
],
plugins: [
typescript({ exclude: ['**/__tests__/**/*', '**/__stories__/**/*'] }),
copy({
targets: [{ src: 'src/skeleton.css', dest: 'dist' }],
}),
],
};