Last active
September 15, 2019 11:49
-
-
Save evdama/3ab11903b1d12131e14e3fe8ef5b5f27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @ts-nocheck //TODO: enable remove once there are typings in place | |
| // TODO: uncomment all three eslint() occurrences once eslint warnings and errors are fixed | |
| // for info on emitCSS etc. https://github.com/rollup/rollup-plugin-svelte#extracting-css and https://svelte.dev/docs#svelte_preprocess | |
| import babel from 'rollup-plugin-babel' | |
| import commonjs from 'rollup-plugin-commonjs' | |
| import config from 'sapper/config/rollup.js' | |
| import getPreprocessor from 'svelte-preprocess' | |
| import getTime from 'date-fns/getTime' | |
| import path from 'path' | |
| import postcss from 'rollup-plugin-postcss' | |
| import replace from 'rollup-plugin-replace' | |
| import resolve from 'rollup-plugin-node-resolve' | |
| import svelte from 'rollup-plugin-svelte' | |
| import { eslint } from 'rollup-plugin-eslint' | |
| import { terser } from 'rollup-plugin-terser' | |
| import pkg from './package.json' | |
| import conf from './config/config' | |
| const appConfig = Object.keys(conf).reduce((acc, n) => { | |
| acc[`process.env.${n}`] = JSON.stringify(conf[n]) | |
| return acc | |
| }, {}) | |
| const mode = process.env.NODE_ENV | |
| const dev = mode === 'development' | |
| const legacy = !!process.env.SAPPER_LEGACY_BUILD | |
| class SvelteExtractor { | |
| static extract(content) { | |
| const regExp = new RegExp(/[A-Za-z0-9-_:/]+/g) | |
| const matchedTokens = [] | |
| let match = regExp.exec(content) | |
| while (match) { | |
| if (match[0].startsWith('class:')) { | |
| matchedTokens.push(match[0].substring(6)) | |
| } else { | |
| matchedTokens.push(match[0]) | |
| } | |
| match = regExp.exec(content) | |
| } | |
| return matchedTokens | |
| } | |
| } | |
| const postcssPlugins = (purgecss = false) => | |
| [ | |
| require('postcss-import')(), | |
| require('postcss-url')(), | |
| require('tailwindcss')({ config: 'tailwind.config.js' }), | |
| require('autoprefixer')({ | |
| overrideBrowserslist: 'last 1 version', | |
| }), | |
| // Do not purge the CSS in dev mode to be able to play with classes in the browser dev-tools. | |
| purgecss && | |
| require('@fullhuman/postcss-purgecss')({ | |
| content: [ | |
| './src/**/*.html', | |
| './src/**/*.svelte', | |
| './src/**/*.css', | |
| './static/**/*.css', | |
| ], | |
| extractors: [ | |
| { | |
| extractor: SvelteExtractor, | |
| // Specify the file extensions to include when scanning for | |
| // class names. | |
| extensions: ['svelte', 'css', 'html'], | |
| }, | |
| ], | |
| fontFace: true, | |
| // Whitelist selectors to stop Purgecss from removing them from your CSS. | |
| whitelist: ['html', 'body'], | |
| }), | |
| purgecss && | |
| require('cssnano')({ | |
| preset: 'default', | |
| }), | |
| ].filter(Boolean) | |
| const preprocess = getPreprocessor({ | |
| transformers: { | |
| postcss: { | |
| plugins: postcssPlugins(), // Don't need purgecss because Svelte handle unused css for you. | |
| }, | |
| }, | |
| }) | |
| const onwarn = (warning, onwarn) => | |
| (warning.code === 'CIRCULAR_DEPENDENCY' && | |
| /[/\\]@sapper[/\\]/.test(warning.message)) || | |
| onwarn(warning) | |
| const dedupe = importee => | |
| importee === 'svelte' || importee.startsWith('svelte/') | |
| export default { | |
| client: { | |
| input: config.client.input(), | |
| output: config.client.output(), | |
| plugins: [ | |
| // eslint(), | |
| replace({ | |
| 'process.browser': true, | |
| 'process.env.NODE_ENV': JSON.stringify(mode), | |
| edmUpdateTimestamp: getTime( new Date() ), | |
| ...appConfig | |
| }), | |
| svelte({ | |
| dev, | |
| hydratable: true, | |
| emitCss: false, | |
| preprocess, | |
| }), | |
| resolve({ | |
| browser: true, | |
| dedupe, | |
| }), | |
| commonjs(), | |
| legacy && | |
| babel({ | |
| extensions: ['.js', '.mjs', '.html', '.svelte'], | |
| runtimeHelpers: true, | |
| exclude: ['node_modules/@babel/**'], | |
| presets: [ | |
| [ | |
| '@babel/preset-env', | |
| { | |
| targets: '> 0.25%, not dead', | |
| }, | |
| ], | |
| ], | |
| plugins: [ | |
| '@babel/plugin-syntax-dynamic-import', | |
| [ | |
| '@babel/plugin-transform-runtime', | |
| { | |
| useESModules: true, | |
| }, | |
| ], | |
| ], | |
| }), | |
| !dev && | |
| terser({ | |
| module: true, | |
| }), | |
| ], | |
| onwarn, | |
| }, | |
| server: { | |
| input: config.server.input(), | |
| output: config.server.output(), | |
| plugins: [ | |
| // eslint(), | |
| replace({ | |
| 'process.browser': false, | |
| 'process.env.NODE_ENV': JSON.stringify(mode), | |
| edmUpdateTimestamp: getTime(new Date()), | |
| }), | |
| svelte({ | |
| generate: 'ssr', | |
| dev, | |
| preprocess, | |
| }), | |
| resolve({ | |
| dedupe, | |
| }), | |
| commonjs(), | |
| postcss({ | |
| plugins: postcssPlugins(!dev), | |
| extract: path.resolve(__dirname, './static/global.css'), | |
| }), | |
| ], | |
| external: Object.keys(pkg.dependencies).concat( | |
| require('module').builtinModules || | |
| Object.keys(process.binding('natives')) | |
| ), | |
| onwarn, | |
| }, | |
| serviceworker: { | |
| input: config.serviceworker.input(), | |
| output: config.serviceworker.output(), | |
| plugins: [ | |
| // eslint(), | |
| resolve(), | |
| replace({ | |
| 'process.browser': true, | |
| 'process.env.NODE_ENV': JSON.stringify(mode), | |
| edmUpdateTimestamp: getTime(new Date()), | |
| }), | |
| commonjs(), | |
| !dev && terser(), | |
| ], | |
| onwarn, | |
| }, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment