| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import autoprefixer from 'autoprefixer';
- import babel from '@rollup/plugin-babel';
- import browsersync from 'rollup-plugin-browsersync';
- import commonjs from '@rollup/plugin-commonjs';
- import copy from 'rollup-plugin-copy';
- import cssnano from 'cssnano';
- import del from 'rollup-plugin-delete';
- import { eslint } from 'rollup-plugin-eslint';
- import json from '@rollup/plugin-json';
- import path from 'path';
- import postcss from 'rollup-plugin-postcss';
- import resolve from '@rollup/plugin-node-resolve';
- import sourcemaps from 'rollup-plugin-sourcemaps';
- import stylelint from 'stylelint';
- import { terser } from 'rollup-plugin-terser';
- import config from './build.json';
- const printWarning = (message) => {
- if (message.code === 'CIRCULAR_DEPENDENCY') {
- return;
- }
- console.error(message); // eslint-disable-line
- };
- const generateConfiguration = (target, option) => {
- target = target === undefined ? 'development' : target;
- // Common postcs configruation for development and production build.
- let postcssconf = {
- extract: true,
- plugins: [
- autoprefixer(),
- stylelint(),
- (target === 'production' && cssnano())
- ],
- };
- // Browsersync configruation
- let browsersyncconf = {
- server: {
- baseDir: config.path.output,
- index: config.html.index.name, // first html file in array is served as index
- },
- watch: true,
- };
- // Default rollup plugins
- const plugins = {
- development: [sourcemaps()],
- production: [terser()],
- prepare: [
- (option !== 'serve' && del({ targets: [path.join(config.path.output, '/*'), path.join(config.path.build, '/*')] })),
- resolve({browser: true}),
- commonjs(),
- json(),
- eslint({
- extends: ['plugin:json/recommended', 'eslint:recommended'],
- exclude: ['src/css/**', 'src/html/**']
- }),
- babel( { babelHelpers: 'bundled' }),
- ],
- postProcess: [
- postcss(postcssconf),
- copy({
- targets: [
- { src: path.join(config.path.build, '/*.css'), dest: path.join(config.path.output, config.path.css) },
- { src: path.join(config.path.build, '/*.js*'), dest: path.join(config.path.output, config.path.js) },
- { src: path.join(config.path.assets, config.path.js), dest: config.path.output },
- { src: path.join(config.path.assets, config.path.css), dest: config.path.output },
- { src: path.join(config.path.assets, config.path.img), dest: config.path.output },
- { src: path.join(config.path.assets, config.path.fonts), dest: config.path.output },
- ],
- hook: 'writeBundle',
- verbose: true
- }),
- (option === 'serve' && browsersync(browsersyncconf))
- ]
- };
- let rconf = {
- onwarn: printWarning,
- input: path.join(config.path.input, config.path.js, `${config.main}.js`),
- plugins: plugins.prepare.concat(plugins[target], plugins.postProcess), // Concatenate plugin arrays
- output: {
- file: path.join(
- config.path.build,
- `${config.main}${config[target].infix}.js`
- ),
- format: 'iife',
- sourcemap: config[target].sourcemap
- }
- };
- return rconf;
- };
- const rollup_config = generateConfiguration(process.env.NODE_ENV, process.env.NODE_OPT);
- export default rollup_config;
|