153 lines
4.4 KiB
JavaScript
153 lines
4.4 KiB
JavaScript
import path from 'path'
|
|
import resolve from '@rollup/plugin-node-resolve'
|
|
import alias from '@rollup/plugin-alias'
|
|
import replace from '@rollup/plugin-replace'
|
|
import commonjs from '@rollup/plugin-commonjs'
|
|
import babel from '@rollup/plugin-babel'
|
|
import svelte from 'rollup-plugin-svelte'
|
|
import autoPreprocess from 'svelte-preprocess'
|
|
import { terser } from 'rollup-plugin-terser'
|
|
import glslify from 'rollup-plugin-glslify'
|
|
import config from 'sapper/config/rollup'
|
|
import { config as dotenv } from 'dotenv'
|
|
import pkg from './package.json'
|
|
|
|
// Define environment and things
|
|
const mode = process.env.NODE_ENV
|
|
const dev = mode === 'development'
|
|
const legacy = !!process.env.SAPPER_LEGACY_BUILD
|
|
const replaceOptions = {
|
|
'process.env.NODE_ENV': JSON.stringify(mode),
|
|
'process.env.CONFIG': JSON.stringify(dotenv().parsed)
|
|
}
|
|
|
|
// Svelte
|
|
const onwarn = (warning, onwarn) => (warning.code === 'MISSING_EXPORT' && /'preload'/.test(warning.message)) || (warning.code === 'CIRCULAR_DEPENDENCY' && /[/\\]@sapper[/\\]/.test(warning.message)) || onwarn(warning)
|
|
|
|
// Preprocessors
|
|
const preprocess = autoPreprocess({
|
|
scss: {
|
|
includePaths: ['src', 'node_modules'],
|
|
renderSync: true
|
|
},
|
|
postcss: true
|
|
})
|
|
|
|
// Resolve and Alias
|
|
const resolveExtensions = ['.mjs', '.js', '.svelte', '.scss', '.json', '.html']
|
|
const aliases = alias({
|
|
resolve: resolveExtensions,
|
|
entries: [
|
|
{ find: 'utils', replacement: path.resolve(__dirname, 'src/utils') },
|
|
{ find: 'animations', replacement: path.resolve(__dirname, 'src/animations') },
|
|
{ find: 'atoms', replacement: path.resolve(__dirname, 'src/atoms') },
|
|
{ find: 'molecules', replacement: path.resolve(__dirname, 'src/molecules') },
|
|
{ find: 'organisms', replacement: path.resolve(__dirname, 'src/organisms') },
|
|
{ find: 'globe', replacement: path.resolve(__dirname, 'src/globe') },
|
|
]
|
|
})
|
|
|
|
|
|
export default {
|
|
/*
|
|
** Client
|
|
*/
|
|
client: {
|
|
input: config.client.input(),
|
|
output: config.client.output(),
|
|
plugins: [
|
|
// Javascript
|
|
replace({
|
|
'process.browser': true,
|
|
...replaceOptions
|
|
}),
|
|
svelte({
|
|
preprocess,
|
|
emitCss: true,
|
|
compilerOptions: {
|
|
dev,
|
|
hydratable: true,
|
|
}
|
|
}),
|
|
aliases,
|
|
glslify(),
|
|
resolve({
|
|
browser: true,
|
|
extensions: resolveExtensions,
|
|
dedupe: ['svelte']
|
|
}),
|
|
commonjs(),
|
|
legacy && babel({
|
|
extensions: resolveExtensions,
|
|
babelHelpers: 'runtime',
|
|
exclude: ['node_modules/@babel/**']
|
|
}),
|
|
|
|
// Compress Javascript
|
|
!dev && terser({
|
|
module: true
|
|
}),
|
|
],
|
|
preserveEntrySignatures: false,
|
|
onwarn,
|
|
},
|
|
|
|
|
|
/*
|
|
** Server
|
|
*/
|
|
server: {
|
|
input: config.server.input(),
|
|
output: config.server.output(),
|
|
plugins: [
|
|
replace({
|
|
'process.browser': false,
|
|
...replaceOptions
|
|
}),
|
|
svelte({
|
|
preprocess,
|
|
emitCss: false,
|
|
compilerOptions: {
|
|
generate: 'ssr',
|
|
hydratable: true,
|
|
dev,
|
|
}
|
|
}),
|
|
aliases,
|
|
glslify(),
|
|
resolve({
|
|
extensions: resolveExtensions,
|
|
dedupe: ['svelte']
|
|
}),
|
|
commonjs()
|
|
],
|
|
external: Object.keys(pkg.dependencies).concat(require('module').builtinModules),
|
|
preserveEntrySignatures: 'strict',
|
|
onwarn,
|
|
},
|
|
|
|
|
|
/*
|
|
** Service worker
|
|
*/
|
|
// ...(!dev && {
|
|
// serviceworker: {
|
|
// input: config.serviceworker.input(),
|
|
// output: config.serviceworker.output(),
|
|
// plugins: [
|
|
// resolve(),
|
|
// replace({
|
|
// 'process.browser': false,
|
|
// ...replaceOptions
|
|
// }),
|
|
// aliases,
|
|
// glslify(),
|
|
// commonjs(),
|
|
// !dev && terser()
|
|
// ],
|
|
// preserveEntrySignatures: false,
|
|
// onwarn,
|
|
// }
|
|
// })
|
|
}
|