rollup.config.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import autoprefixer from 'autoprefixer';
  2. import babel from '@rollup/plugin-babel';
  3. import browsersync from 'rollup-plugin-browsersync';
  4. import commonjs from '@rollup/plugin-commonjs';
  5. import cssnano from 'cssnano';
  6. import copy from 'rollup-plugin-copy';
  7. // import del from 'rollup-plugin-delete';
  8. // import { eslint } from 'rollup-plugin-eslint';
  9. import json from 'rollup-plugin-json';
  10. import path from 'path';
  11. import postcss from 'rollup-plugin-postcss';
  12. import riot from 'rollup-plugin-riot';
  13. import resolve from '@rollup/plugin-node-resolve';
  14. import sourcemaps from 'rollup-plugin-sourcemaps';
  15. import stylelint from 'stylelint';
  16. import { terser } from 'rollup-plugin-terser';
  17. import config from './build.json';
  18. const printWarning = (message) => {
  19. if (message.code === 'CIRCULAR_DEPENDENCY') {
  20. return;
  21. }
  22. console.error(message); // eslint-disable-line
  23. };
  24. let TARGET = process.env.NODE_ENV || 'development';
  25. let MODE = process.env.NODE_OPT;
  26. export default {
  27. onwarn: printWarning,
  28. input: path.join(config.path.input, config.path.js, `${config.main}.js`),
  29. output: {
  30. file: path.join(config.path.output, config.path.js, `${config.main}${config[TARGET].infix}.js`),
  31. format: 'iife',
  32. sourcemap: config[TARGET].sourcemap
  33. },
  34. plugins: [
  35. // (MODE !== 'serve' && del({ targets: [path.join(config.path.output, '/*'), path.join(config.path.output, '/*')] })),
  36. resolve({ browser: true }),
  37. json(),
  38. commonjs(),
  39. // eslint({
  40. // exclude: ['styles/**', 'context/**', 'html/**']
  41. // }),
  42. riot(),
  43. babel({ babelHelpers: 'bundled' }),
  44. (TARGET === 'development' && sourcemaps()),
  45. postcss({
  46. extract: `${config.main}${config[TARGET].infix}.css`, // rollup v3 seems to have broken the convenient way. file needs to be copied to destination in succeeding step
  47. plugins: [
  48. autoprefixer(),
  49. stylelint(),
  50. (TARGET === 'production' && cssnano())
  51. ]
  52. }),
  53. copy({
  54. targets: [
  55. { src: path.join(config.path.output, config.path.js, `${config.main}${config[TARGET].infix}.css`), dest: path.join(config.path.output, config.path.css) },
  56. { src: path.join(config.path.data, config.data), dest: path.join(config.path.output, config.path.data) },
  57. { src: path.join(config.path.assets, config.path.js), dest: config.path.output },
  58. { src: path.join(config.path.assets, config.path.img), dest: config.path.output },
  59. { src: path.join(config.path.assets, config.path.fonts), dest: config.path.output },
  60. ],
  61. hook: 'writeBundle',
  62. verbose: true
  63. }),
  64. (TARGET === 'production' && terser()),
  65. (MODE === 'serve' && browsersync({
  66. server: {
  67. baseDir: config.path.output,
  68. index: config.html.output
  69. }
  70. }))
  71. ]
  72. };