-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathrollup.config.mjs
128 lines (125 loc) · 4.1 KB
/
rollup.config.mjs
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
import { nodeResolve } from '@rollup/plugin-node-resolve';
import multi from '@rollup/plugin-multi-entry';
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy';
import styles from "rollup-plugin-styler";
import postCSSReplace from 'postcss-replace';
const paths = {
src: 'app/assets/',
dist: 'app/static/',
npm: 'node_modules/',
govuk_frontend: 'node_modules/govuk-frontend/dist/'
};
const isDevelopment = Boolean(process.env.NOTIFY_ENVIRONMENT === 'development')
export default [
// ESM compilation and copy static assets
{
input: paths.src + 'javascripts/esm/all-esm.mjs',
output: {
dir: paths.dist + 'javascripts/',
entryFileNames: 'all-esm.mjs',
format: 'es',
sourcemap: true
},
plugins: [
nodeResolve(),
terser(),
// copy images, error pages and govuk-frontend static assets
copy({
targets: [
{ src: paths.src + 'error_pages/**/*', dest: paths.dist + 'error_pages/' },
{ src: [ paths.src + 'images/**/*', paths.govuk_frontend + 'govuk/assets/images/**/*' ], dest: paths.dist + 'images/' },
{ src: paths.govuk_frontend + 'govuk/assets/fonts/**/*', dest: paths.dist + 'fonts/' },
{ src: paths.govuk_frontend + 'govuk/assets/manifest.json', dest: paths.dist }
]
}),
]
},
// SCSS compilation
{
input: [
paths.src + 'stylesheets/main.scss',
paths.src + 'stylesheets/print.scss'
],
output: {
dir: paths.dist + 'stylesheets/',
assetFileNames: "[name][extname]",
},
plugins: [
// https://anidetrix.github.io/rollup-plugin-styles/interfaces/types.Options.html
styles({
mode: "extract",
sass: {
includePaths: [
paths.govuk_frontend,
paths.npm
],
},
minimize: true,
url: false,
sourceMap: true,
plugins:[
// Rewrite /static prefix for URLs in CSS files for production
!isDevelopment && postCSSReplace({
pattern: /\/static\//g,
data: {
replaceAll: '/'
}
}),
]
}),
]
},
// ES5 JS compilation
{
input: [
paths.npm + 'jquery/dist/jquery.min.js',
paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js',
paths.npm + 'timeago/jquery.timeago.js',
paths.npm + 'textarea-caret/index.js',
paths.npm + 'cbor-js/cbor.js',
paths.src + 'javascripts/modules.js',
paths.src + 'javascripts/govuk-frontend-toolkit/show-hide-content.js',
paths.src + 'javascripts/stick-to-window-when-scrolling.js',
paths.src + 'javascripts/cookieCleanup.js',
paths.src + 'javascripts/copyToClipboard.js',
paths.src + 'javascripts/enhancedTextbox.js',
paths.src + 'javascripts/radioSelect.js',
paths.src + 'javascripts/updateContent.js',
paths.src + 'javascripts/listEntry.js',
paths.src + 'javascripts/liveSearch.js',
paths.src + 'javascripts/preventDuplicateFormSubmissions.js',
paths.src + 'javascripts/fullscreenTable.js',
paths.src + 'javascripts/radios-with-images.js',
paths.src + 'javascripts/previewPane.js',
paths.src + 'javascripts/liveCheckboxControls.js',
paths.src + 'javascripts/templateFolderForm.js',
paths.src + 'javascripts/addBrandingOptionsForm.js',
paths.src + 'javascripts/setAuthTypeForm.js',
paths.src + 'javascripts/registerSecurityKey.js',
paths.src + 'javascripts/authenticateSecurityKey.js',
paths.src + 'javascripts/updateStatus.js',
paths.src + 'javascripts/errorBanner.js',
paths.src + 'javascripts/homepage.js',
paths.src + 'javascripts/removeInPresenceOf.js',
paths.src + 'javascripts/main.js',
],
output: {
dir: paths.dist + 'javascripts/',
sourcemap: true
},
moduleContext: {
'./node_modules/jquery/dist/jquery.min.js': 'window',
'./node_modules/cbor-js/cbor.js': 'window',
},
plugins: [
nodeResolve(),
multi({
entryFileName: 'all.js'
}),
terser({
ecma: '5'
}),
]
}
];