-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrollup.config.js
More file actions
129 lines (120 loc) · 4.36 KB
/
Copy pathrollup.config.js
File metadata and controls
129 lines (120 loc) · 4.36 KB
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
import svelte from 'rollup-plugin-svelte-hot';
import Hmr from 'rollup-plugin-hot'
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 { copySync, removeSync } from 'fs-extra'
import { spassr } from 'spassr'
import getConfig from '@roxi/routify/lib/utils/config'
import autoPreprocess from 'svelte-preprocess'
import postcssImport from 'postcss-import'
import { injectManifest } from 'rollup-plugin-workbox'
import { mdsvex } from "mdsvex";
import smartAsset from "rollup-plugin-smart-asset";
import json from '@rollup/plugin-json';
import replace from 'rollup-plugin-replace';
const { distDir } = getConfig() // use Routify's distDir for SSOT
const assetsDir = 'assets'
const buildDir = `dist/build`
const isNollup = !!process.env.NOLLUP
const production = !process.env.ROLLUP_WATCH;
// clear previous builds
removeSync(distDir)
removeSync(buildDir)
const serve = () => ({
writeBundle: async () => {
const options = {
assetsDir: [assetsDir, distDir],
entrypoint: `${assetsDir}/__app.html`,
script: `${buildDir}/main.js`
}
spassr({ ...options, port: 5000 })
spassr({ ...options, ssr: true, port: 5005, ssrOptions: { inlineDynamicImports: true, dev: true } })
}
})
const copyToDist = () => ({ writeBundle() { copySync(assetsDir, distDir) } })
export default {
preserveEntrySignatures: false,
input: [`src/main.js`],
output: {
sourcemap: true,
format: 'esm',
dir: buildDir,
// for performance, disabling filename hashing in development
chunkFileNames:`[name]${production && '-[hash]' || ''}.js`
},
onwarn: (warning, handler) => {
const ignoredWarnings = [
'CIRCULAR_DEPENDENCY',
];
if (!ignoredWarnings.includes(warning.code)) handler(warning)
},
plugins: [
svelte({
dev: !production, // run-time checks
// Extract component CSS — better performance
css: css => css.write(`bundle.css`),
hot: isNollup,
extensions: [".svelte", ".svx", ".html"],
preprocess: [
mdsvex(),
autoPreprocess({
postcss: { plugins: [postcssImport()] },
defaults: { style: 'scss' },
scss: {
prependData: "@import 'assets/styles/variables.scss';",
includePaths: ["assets/styles", "node_modules"],
}
})
],
onwarn: (warning, handler) => {
const ignoredWarnings = [
'a11y-media-has-caption',
];
if (!ignoredWarnings.includes(warning.code)) handler(warning)
}
}),
json(),
smartAsset({
url: "copy",
assetsPath: "images",
publicPath: "/build/images/",
useHash: true,
extensions: [".svg", ".gif", ".png", ".jpg", ".mp3", ".csv"],
}),
// resolve matching modules from current working directory
resolve({
browser: true,
dedupe: importee => !!importee.match(/svelte(\/|$)/)
}),
commonjs(),
production && terser(),
!production && !isNollup && serve(),
!production && !isNollup && livereload(distDir), // refresh entire window when code is updated
!production && isNollup && Hmr({ inMemory: true, public: assetsDir, }), // refresh only updated code
{
// provide node environment on the client
transform: code => ({
code: code.replace('process.env.NODE_ENV', `"${process.env.NODE_ENV}"`),
map: { mappings: '' }
})
},
replace({
'process.env.NODE_ENV': `"${production ? 'production' : 'development'}"`,
}),
injectManifest({
globDirectory: assetsDir,
globPatterns: ['**/*.{js,css,svg}', '__app.html'],
swSrc: `src/sw.js`,
swDest: `dist/serviceworker.js`,
maximumFileSizeToCacheInBytes: 10000000, // 10 MB,
mode: 'production'
}),
production && copyToDist(),
],
watch: {
clearScreen: false,
buildDelay: 100,
}
}