-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathrollup.config.js
80 lines (77 loc) · 2.61 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
import path from 'path'
import linaria from 'linaria/rollup'
import css from 'rollup-plugin-css-only'
import alias from '@rollup/plugin-alias'
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import replace from '@rollup/plugin-replace'
import copy from 'rollup-plugin-copy'
import resolve from '@rollup/plugin-node-resolve'
import { chromeExtension } from 'rollup-plugin-chrome-extension'
import { emptyDir } from 'rollup-plugin-empty-dir'
import zip from 'rollup-plugin-zip'
import keys from './keys.json' // See README on how to get a key
const isRelease = process.env.IS_RELEASE === 'true'
const projectRootDir = path.resolve(__dirname)
export default {
input: 'src/manifest.json',
output: {
dir: 'build',
format: 'esm',
chunkFileNames: path.join('chunks', '[name]-[hash].js'),
},
onwarn: function onwarn(warning, warn) {
if (warning.code === 'FILE_NAME_CONFLICT') return // We are require to conflict due to manifest
warn(warning)
},
plugins: [
chromeExtension({ verbose: false }),
alias({
entries: {
actions: path.resolve(projectRootDir, 'src/actions.js'),
assets: path.resolve(projectRootDir, 'src/assets'),
common: path.resolve(projectRootDir, 'src/common'),
components: path.resolve(projectRootDir, 'src/components'),
connectors: path.resolve(projectRootDir, 'src/connectors'),
containers: path.resolve(projectRootDir, 'src/containers'),
pages: path.resolve(projectRootDir, 'src/pages'),
_locales: path.resolve(projectRootDir, 'src/_locales')
},
}),
// Replace environment variables
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.IS_RELEASE': JSON.stringify(process.env.IS_RELEASE)
}),
replace({
preventAssignment: false,
__consumerKey__: keys.chrome,
}),
resolve(),
commonjs({
exclude: 'src/**',
}),
linaria(),
json(),
babel({
// Do not transpile dependencies
ignore: ['node_modules'],
babelHelpers: 'bundled',
}),
css({ output: 'assets/pocket-save-extension.css' }),
// Empties the output dir before a new build
emptyDir(),
copy({
targets: [
{ src: 'src/assets/fonts/*', dest: 'build/assets/fonts' },
{ src: 'src/assets/images/*', dest: 'build/assets/images' },
{ src: 'src/_locales/*', dest: 'build/_locales' },
],
hook: 'writeBundle',
}),
// Outputs a zip file in ./releases
isRelease && zip({ dir: 'releases' }),
],
}