rollup.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import resolve from 'rollup-plugin-node-resolve';
  2. import replace from 'rollup-plugin-replace';
  3. import commonjs from 'rollup-plugin-commonjs';
  4. import svelte from 'rollup-plugin-svelte';
  5. import babel from 'rollup-plugin-babel';
  6. import { terser } from 'rollup-plugin-terser';
  7. import config from 'sapper/config/rollup.js';
  8. import pkg from './package.json';
  9. import typescript from 'rollup-plugin-typescript2';
  10. import autoPreprocess from 'svelte-preprocess';
  11. const mode = process.env.NODE_ENV;
  12. const dev = mode === 'development';
  13. const legacy = !!process.env.SAPPER_LEGACY_BUILD;
  14. const onwarn = (warning, onwarn) => (warning.code === 'CIRCULAR_DEPENDENCY' && /[/\\]@sapper[/\\]/.test(warning.message)) || onwarn(warning);
  15. const dedupe = importee => importee === 'svelte' || importee.startsWith('svelte/');
  16. const preprocessOptions = {
  17. scss: false,
  18. transformers: {
  19. // scss: {
  20. // includePaths: [
  21. // 'node_modules',
  22. // 'src'
  23. // ]
  24. // },
  25. postcss: {
  26. plugins: [
  27. require('postcss-import'),
  28. require('tailwindcss'),
  29. require('postcss-nested'),
  30. require('autoprefixer'),
  31. ]
  32. }
  33. },
  34. }
  35. export default {
  36. client: {
  37. input: config.client.input(),
  38. output: config.client.output(),
  39. plugins: [
  40. replace({
  41. 'process.browser': true,
  42. 'process.env.NODE_ENV': JSON.stringify(mode)
  43. }),
  44. svelte({
  45. dev,
  46. hydratable: true,
  47. emitCss: true,
  48. preprocess: autoPreprocess(preprocessOptions)
  49. }),
  50. resolve({
  51. browser: true,
  52. dedupe
  53. }),
  54. commonjs(),
  55. legacy && babel({
  56. extensions: ['.js', '.mjs', '.html', '.svelte'],
  57. runtimeHelpers: true,
  58. exclude: ['node_modules/@babel/**'],
  59. presets: [
  60. ['@babel/preset-env', {
  61. targets: '> 0.25%, not dead'
  62. }]
  63. ],
  64. plugins: [
  65. '@babel/plugin-syntax-dynamic-import',
  66. ['@babel/plugin-transform-runtime', {
  67. useESModules: true
  68. }]
  69. ]
  70. }),
  71. !dev && terser({
  72. module: true
  73. })
  74. ],
  75. onwarn,
  76. },
  77. server: {
  78. input: { server: config.server.input().server.replace(/\.js$/, '.ts') },
  79. output: {
  80. ...config.server.output(),
  81. sourcemap: process.env.NODE_ENV == "development"
  82. },
  83. plugins: [
  84. replace({
  85. 'process.browser': false,
  86. 'process.env.NODE_ENV': JSON.stringify(mode)
  87. }),
  88. svelte({
  89. generate: 'ssr',
  90. dev,
  91. preprocess: autoPreprocess(preprocessOptions)
  92. }),
  93. resolve({
  94. dedupe,
  95. extensions: ['.mjs', '.js', '.ts', '.json']
  96. }),
  97. commonjs(),
  98. typescript()
  99. ],
  100. external: Object.keys(pkg.dependencies).concat(
  101. require('module').builtinModules || Object.keys(process.binding('natives'))
  102. ),
  103. onwarn,
  104. },
  105. serviceworker: {
  106. input: config.serviceworker.input(),
  107. output: config.serviceworker.output(),
  108. plugins: [
  109. resolve(),
  110. replace({
  111. 'process.browser': true,
  112. 'process.env.NODE_ENV': JSON.stringify(mode)
  113. }),
  114. commonjs(),
  115. !dev && terser()
  116. ],
  117. onwarn,
  118. }
  119. };