-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
153 lines (147 loc) · 4.08 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { readFileSync, writeFileSync } from 'fs'
import path, { resolve } from 'path';
import postcss from 'rollup-plugin-postcss'
import babel from '@rollup/plugin-babel';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import alias from '@rollup/plugin-alias';
import { terser } from "rollup-plugin-terser";
import { replaceWord } from './plugin';
const pkg = require('./package.json');
console.log('Process ===> ', process.env.BROWSER, process.env.NODE_ENV);
const isChrome = process.env.BROWSER === undefined ? true : process.env.BROWSER === 'chrome';
const from = isChrome ? 'browser' : 'chrome';
const to = isChrome ? 'chrome' : 'browser';
if (!isChrome) {
const content = readFileSync(resolve(process.cwd(), 'manifest-v2.json'), 'utf8');
writeFileSync(resolve(process.cwd(), 'dist', 'manifest.json'), content);
}
const isProduction = process.env.NODE_ENV === 'production';
const banner = `/*! Reco - v${pkg.version} | Copyright 2022 - Haikel Fazzani */\n`;
export default [
{
input: "src/background/index.js",
output: {
file: "dist/background.js",
format: "iife",
sourcemap: !isProduction,
banner
},
plugins: [
replaceWord({ from, to }),
isProduction ? terser() : ''
]
},
{
input: "src/editor/index.js",
output: {
file: "dist/editor.js",
format: "iife",
sourcemap: !isProduction,
banner
},
plugins: [
postcss({
extract: true,
minimize: isProduction,
extract: path.resolve('dist/editor.css')
}),
replaceWord({ from, to }),
isProduction ? terser() : ''
]
},
{
input: "src/permission/index.js",
output: {
file: "dist/permission.js",
format: "iife",
sourcemap: !isProduction,
banner
},
plugins: [
postcss({
extract: true,
minimize: isProduction,
extract: path.resolve('dist/permission.css')
}),
replaceWord({ from, to }),
isProduction ? terser() : ''
]
},
{
input: "src/popup/index.js",
output: {
file: "dist/popup.js",
format: "iife",
sourcemap: !isProduction,
banner
},
plugins: [
alias({
entries: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom/test-utils', replacement: 'preact/test-utils' },
{ find: 'react-dom', replacement: 'preact/compat' },
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' }
]
}),
nodeResolve({
extensions: [".js"],
}),
babel({
babelHelpers: 'runtime',
presets: ["@babel/preset-react"],
plugins: [
"@babel/plugin-transform-runtime",
["@babel/plugin-transform-react-jsx", { pragma: "h", pragmaFrag: "Fragment", }]
],
}),
postcss({
extract: true,
minimize: isProduction,
extract: path.resolve('dist/popup.css')
}),
commonjs(),
replaceWord({ from, to }),
isProduction ? terser() : ''
]
},
{
input: "src/content/index.js",
output: {
file: "dist/content.js",
format: "iife",
sourcemap: !isProduction,
banner
},
plugins: [
alias({
entries: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom/test-utils', replacement: 'preact/test-utils' },
{ find: 'react-dom', replacement: 'preact/compat' },
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' }
]
}),
nodeResolve({
extensions: [".js"],
}),
babel({
babelHelpers: 'runtime',
presets: ["@babel/preset-react"],
plugins: [
"@babel/plugin-transform-runtime",
["@babel/plugin-transform-react-jsx", { pragma: "h", pragmaFrag: "Fragment", }]
],
}),
postcss({
extract: true,
minimize: isProduction,
extract: path.resolve('dist/content.css')
}),
commonjs(),
replaceWord({ from, to }),
isProduction ? terser() : ''
]
}
];