|
| 1 | +import path from "path"; |
| 2 | + |
| 3 | +import gulp from "gulp"; |
| 4 | +import {rollup} from 'rollup'; |
| 5 | +import alias from "rollup-plugin-alias"; |
| 6 | +import json from "rollup-plugin-json"; |
| 7 | +import svelte from "rollup-plugin-svelte"; |
| 8 | +import resolve from "rollup-plugin-node-resolve"; |
| 9 | +import commonjs from "rollup-plugin-commonjs"; |
| 10 | +import buble from "rollup-plugin-buble"; |
| 11 | +import {terser} from "rollup-plugin-terser"; |
| 12 | + |
| 13 | +import pkg from "../package.json"; |
| 14 | + |
| 15 | +import {makeResolveAliases} from "../src/utils/buildUtils"; |
| 16 | + |
| 17 | +import {SRC_PATH, BUILD_PATH} from "./index"; |
| 18 | +import options from "./options"; |
| 19 | + |
| 20 | +const isProductionBuild = options.production; |
| 21 | +const resolveAliases = makeResolveAliases(path.resolve(__dirname, "../")); |
| 22 | + |
| 23 | +const bundleOpts = { |
| 24 | + input: "src/app/main.js", |
| 25 | + plugins: [ |
| 26 | + alias(resolveAliases({ |
| 27 | + "@utils": "src/utils", |
| 28 | + "@data": "data" |
| 29 | + })), |
| 30 | + resolve(), |
| 31 | + commonjs(), |
| 32 | + json(), |
| 33 | + svelte({ |
| 34 | + skipIntroByDefault: true, |
| 35 | + nestedTransitions: true, |
| 36 | + dev: !isProductionBuild, |
| 37 | + |
| 38 | + // bundle all components CSS into a single file |
| 39 | + css: css => { |
| 40 | + css.write(`${BUILD_PATH}/bundle.css`, !isProductionBuild); |
| 41 | + } |
| 42 | + }), |
| 43 | + |
| 44 | + isProductionBuild && buble(), |
| 45 | + isProductionBuild && terser() |
| 46 | + ], |
| 47 | + cache: true |
| 48 | +}; |
| 49 | + |
| 50 | +const outputOpts = { |
| 51 | + file: "build/bundle.js", |
| 52 | + format: "iife", |
| 53 | + name: pkg.name, |
| 54 | + sourcemap: !isProductionBuild, |
| 55 | +}; |
| 56 | + |
| 57 | +gulp.task("rollup", async function (done) { |
| 58 | + const bundle = await rollup(bundleOpts); |
| 59 | + await bundle.write(outputOpts); |
| 60 | + |
| 61 | + done(); |
| 62 | +}); |
| 63 | + |
| 64 | +gulp.task("watch.src", done => { |
| 65 | + gulp.watch(SRC_PATH, gulp.task("rollup")); |
| 66 | + |
| 67 | + done(); |
| 68 | +}); |
0 commit comments