How to use ROLLUP_CACHE method in Best

Best JavaScript code snippet using best

gulpfile-rollup-variants.js

Source:gulpfile-rollup-variants.js Github

copy

Full Screen

1var path = require("path");2var fs = require("fs");3var jetpack = require('fs-jetpack')4var del = require("del");5var browserify = require("browserify");6var watchify = require("watchify");7var envify = require('loose-envify/custom')8const hmr = require("./tools/devserver/hmr-plugin");9const aliasify = require("./tools/transforms/aliasify");10var { sucrasify } = require("./tools/transforms/sucrasify");11var discify = require("discify")12var gulp = require("gulp");13var FwdRef = require("undertaker-forward-reference");14gulp.registry(FwdRef());15var babel = require("gulp-babel");16var clip = require('gulp-clip-empty-files')17var gulp_typescript = require("gulp-typescript");18var livereload = require("gulp-livereload");19var concat = require("gulp-concat");20var less = require("gulp-less");21var rename = require('gulp-rename')22var rollup = require("./tools/gulptasks/gulp-rollup");23var closure = require('@ampproject/rollup-plugin-closure-compiler')24const {terser} = require('rollup-plugin-terser')25var typescript = gulp_typescript.createProject("tsconfig.json", {26 module: "esnext",27 target: "esnext",28 importHelpers: true,29 removeComments: true,30 allowJs: true,31 jsx: "react",32 jsxFactory: "h",33 experimentalDecorators: true,34 noResolve: true,35 isolatedModules: true,36 skipLibCheck: true37});38gulp.task("clean", () => del(["dist"]));39gulp.task("ts", () => {40 return gulp41 .src(["src/**/*.{tsx,ts,jsx,js}", "!src/**/*.{spec,test}.*"])42 .pipe(typescript())43 .pipe(gulp.dest("build"));44});45gulp.task("html", () => {46 const isDev = true47 if(isDev)48 return gulp49 .src(["src/public/index.development.html"])50 .pipe(rename("index.html"))51 .pipe(gulp.dest("build/public"))52 .pipe(livereload());53 54 if(!isDev)55 return gulp56 .src(["src/public/index.production.html"])57 .pipe(rename("index.html"))58 .pipe(gulp.dest("build/public"))59});60gulp.task("styles", async () => {61 gulp62 .src(["src/**/*.{css,less}", "!src/public/**/*"])63 .pipe(concat("styles.less"))64 .pipe(less())65 //.pipe(postcss())66 .pipe(gulp.dest("build/public"))67 .pipe(livereload());68});69const b = watchify(70 browserify({71 entries: ["build/app/main.js"],72 extensions: [".ts", ".tsx", ".js", ".jsx"],73 cache: {},74 packageCache: {},75 debug: false,76 sourceMaps: false,77 fullPaths: true78 //dedupe: true79 })80);81b.plugin(discify, {outdir: "build/public/disc"})82b.plugin(hmr);83b.transform(sucrasify);84b.transform([85 envify({86 NODE_ENV: "development"87 }), {global: true}88])89b.transform([90 aliasify.configure({91 aliases: {92 //"react": "react/cjs/react.production.min.js",93 //"react-dom": "react-dom/cjs/react-dom.production.min.js"94 //"react-dom": "react-dom/cjs/react-dom.profiling.min.js",95 "react": "preact/compat",96 "react-dom": "preact/compat"97 },98 appliesTo: { includeExtensions: [".js", ".jsx", ".tsx", ".ts"] }99 }),100 { global: true }101]);102b.on("error", console.log);103b.on("syntax", console.log);104b.on("update", bundle);105async function bundle() {106 b.bundle()107 .on("error", console.error)108 .pipe(fs.createWriteStream("build/public/main.js"));109}110gulp.task("rollit", function () {111 return (112 gulp.src(["./src/**/*{.js,.jsx,.ts,.tsx}"])113 .pipe(typescript())114 .pipe(babel())115 .pipe(116 rollup({117 input: "src/app/main.js",118 output: {119 format: "esm"120 },121 external: Object.keys(require("./package.json").dependencies),122 treeshake: {123 moduleSideEffects: false124 },125 inlineDynamicImports: true,126 plugins: [127 //terser(),128 //closure()129 ],130 onwarn: function(message) {131 if (/external dependency/.test(message)) {132 return133 }134 if (message.code === 'CIRCULAR_DEPENDENCY') {135 return136 }137 if (message.code === 'INPUT_HOOK_IN_OUTPUT_PLUGIN') {138 return139 }140 else console.error(message)141 },142 })143 )144 .pipe(gulp.dest("build/public"))145 );146});147var ROLLUP_CACHE = {}148gulp.task("rollit:cjs", function () {149 return (150 gulp.src(["./src/**/*{.js,.jsx,.ts,.tsx}"])151 .pipe(typescript())152 .pipe(babel())153 .pipe(154 rollup({155 //cache: ROLLUP_CACHE,156 separateCaches: ROLLUP_CACHE,157 input: "src/app/main.js",158 output: {159 format: "cjs"160 },161 external: Object.keys(require("./package.json").dependencies),162 treeshake: {163 moduleSideEffects: false164 },165 inlineDynamicImports: true,166 plugins: [167 //terser(),168 //closure()169 ],170 onwarn: function(message) {171 if (/external dependency/.test(message)) {172 return173 }174 if (message.code === 'CIRCULAR_DEPENDENCY') {175 return176 }177 if (message.code === 'INPUT_HOOK_IN_OUTPUT_PLUGIN') {178 return179 }180 else console.error(message)181 },182 })183 )184 .on('bundle', function(bundle, name) {185 ROLLUP_CACHE[name] = bundle;186 })187 .pipe(rename("main.js"))188 .pipe(gulp.dest("build"))189 );190});191gulp.task("rollit:minify", function () {192 return (193 gulp.src(["./src/**/*{.js,.jsx,.ts,.tsx}"])194 .pipe(typescript())195 .pipe(babel())196 .pipe(197 rollup({198 input: "src/app/main.js",199 output: {200 format: "esm",201 dir: "build"202 },203 external: Object.keys(require("./package.json").dependencies),204 treeshake: {205 moduleSideEffects: false206 },207 inlineDynamicImports: true,208 plugins: [209 terser(),210 closure()211 ]212 })213 )214 .pipe(rename("main.min.js"))215 .pipe(gulp.dest("build"))216 );217});218const serve = () => {219 const { polka, sirv } = require("./tools/devserver");220 const { PORT = 3002 } = process.env;221 const PUBLIC_INDEX_HTML = fs.readFileSync(222 path.resolve(__dirname, "build/public", "index.html")223 );224 const allowAMP = res =>225 res.setHeader(226 "AMP-Access-Control-Allow-Source-Origin",227 `http://localhost:${PORT}`228 );229 polka()230 .use(231 sirv(path.resolve(__dirname, "build/public"), {232 dev: true,233 setHeaders: res => allowAMP(res)234 })235 )236 .get("*", (req, res) => {237 res.end(PUBLIC_INDEX_HTML);238 })239 .listen(PORT, () => {240 console.log(`> Running on http://localhost:${PORT}`);241 console.log(`> BundleAnalyzer on http://localhost:${PORT}/disc/map`);242 });243};244gulp.task("watch", async () => {245 livereload.listen();246 gulp.watch("src/**/*.{css,less}", gulp.series("styles"));247 gulp.watch("src/**/*.html", gulp.series("html"));248 gulp.watch("src/**/*.{ts,tsx,js,jsx}", gulp.series("rollit:cjs"));249});250gulp.task(251 "start",252 gulp.series(253 "clean",254 gulp.parallel("rollit:cjs", "styles", "html"),255 gulp.parallel(bundle, "watch", serve)256 )257);258// .pipe(source('main.js'))259// .pipe(buffer())260// .pipe(sourcemaps.init({ loadMaps: true }))261// .pipe(minify())262// .pipe(sourcemaps.write('./'))263// .pipe(gulp.dest('build/js'))264//externalizes stuff so you can use unpkg265// .transform('browserify-shim', {266// "lodash": "_",267// "react": "React",268// "react-dom": "ReactDOM"269// }, {global: true});270//you can skip writing files and just use 'browserify-middleware' package if you want to do this271//.get('/main.js', browserifyMiddleware(__dirname+'/src/app.tsx'))272//windows users can use this273//const {watchify} = require("./tools/transforms/watchify");274// this is poor mans tsconfig paths / babel root import resolver, its a browserify transform275//var {tspathify} = require('./tools/transforms/tspathify')276//undertaker is ass, this makes it a little less so277//var FwdRef = require("undertaker-forward-reference");278/**279 * this files tsconfig at the top doesnt check types, although a good strategy 280 * is to change the config to do type checks and to not emit on errors281 * by setting noEmitOnError: true. The compiled javascript files won't hit the 282 * build dir so no pressure on the watcher and it won't run hmr until the code compiles283*/284// wtb pt 96 font...

Full Screen

Full Screen

build-benchmark.ts

Source:build-benchmark.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import fs from 'fs';8import { rollup, OutputOptions } from 'rollup';9import path from 'path';10import crypto from 'crypto';11import mkdirp from "mkdirp";12import benchmarkRollup from './rollup-plugin-benchmark-import';13import generateHtml from './html-templating';14import { FrozenGlobalConfig, FrozenProjectConfig, ProjectConfigPlugin, BuildConfig } from '@best/types';15import { req } from '@best/utils';16const BASE_ROLLUP_OUTPUT: OutputOptions = { format: 'iife' };17const ROLLUP_CACHE = new Map();18function md5(data: string) {19 return crypto.createHash('md5').update(data).digest('hex');20}21function addResolverPlugins(plugins: ProjectConfigPlugin[]): any[] {22 if (!plugins) {23 return [];24 }25 return plugins.map((plugin: ProjectConfigPlugin) => {26 if (typeof plugin === 'string') {27 return req(plugin)();28 } else if (Array.isArray(plugin)) {29 return req(plugin[0])(plugin[1]);30 } else {31 throw new Error('Invalid plugin config');32 }33 });34}35interface BuildOutputMessager {36 onBenchmarkBuildStart(benchmarkPath: string): void;37 onBenchmarkBuildEnd(benchmarkPath: string): void;38 log(message: string): void;39}40export async function buildBenchmark(entry: string, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, buildLogStream: BuildOutputMessager): Promise<BuildConfig> {41 buildLogStream.onBenchmarkBuildStart(entry);42 const { gitInfo: { lastCommit: { hash: gitHash }, localChanges } } = globalConfig;43 const { projectName, benchmarkOutput } = projectConfig;44 const ext = path.extname(entry);45 const benchmarkName = path.basename(entry, ext);46 const benchmarkJSFileName = benchmarkName + ext;47 const benchmarkProjectFolder = path.join(benchmarkOutput, projectName);48 buildLogStream.log('Bundling benchmark files...');49 const bundle = await rollup({50 input: entry,51 plugins: [benchmarkRollup(), ...addResolverPlugins(projectConfig.plugins)],52 cache: ROLLUP_CACHE.get(projectName),53 manualChunks: function () { /* guarantee one chunk */ return 'main_chunk'; },54 onwarn(warning, warn) {55 // Make compilation fail, if any bare module can't be resolved.56 if (typeof warning === 'object' && warning.code === 'UNRESOLVED_IMPORT') {57 throw new Error(warning.message);58 }59 warn(warning);60 }61 });62 ROLLUP_CACHE.set(projectName, bundle.cache);63 buildLogStream.log('Generating benchmark artifacts...');64 const { output } = await bundle.generate(BASE_ROLLUP_OUTPUT);65 const benchmarkSource = output[0].code; // We don't do code splitting so the first one will be the one we want66 // Benchmark artifacts vars67 const benchmarkSignature = md5(benchmarkSource);68 const benchmarkSnapshotName = localChanges ? `${benchmarkName}_local_${benchmarkSignature.slice(0, 10)}` : `${benchmarkName}_${gitHash}`;69 const benchmarkFolder = path.join(benchmarkProjectFolder, benchmarkSnapshotName);70 const benchmarkArtifactsFolder = path.join(benchmarkFolder, 'artifacts');71 const benchmarkEntry = path.join(benchmarkArtifactsFolder, `${benchmarkName}.html`);72 const htmlTemplate = generateHtml({ benchmarkName, benchmarkJs: `./${benchmarkJSFileName}` });73 mkdirp.sync(benchmarkArtifactsFolder);74 fs.writeFileSync(benchmarkEntry, htmlTemplate, 'utf-8');75 fs.writeFileSync(path.join(benchmarkArtifactsFolder, benchmarkJSFileName), benchmarkSource, 'utf-8');76 buildLogStream.onBenchmarkBuildEnd(entry);77 return {78 benchmarkName,79 benchmarkFolder,80 benchmarkEntry,81 benchmarkSignature,82 projectConfig,83 globalConfig,84 };...

Full Screen

Full Screen

rollup.js

Source:rollup.js Github

copy

Full Screen

1import fs from 'fs'2import router from 'koa-route'3import store from '../../store.js'4import { rollup } from 'rollup'5import { join } from 'path'6import { promisify } from 'util'7const ROLLUP_CACHE = store.cache.rollup8const CONFIG = {9 format: 'iife',10 sourceMap: true11}12async function fileExists (path) {13 const absPath = join(process.cwd(), path)14 let result = true15 try {16 await promisify(fs.access)(absPath)17 } catch (error) {18 if (error) {19 result = false20 }21 }22 return result23}24export default function serveJS (PUBLIC_PATH) {25 return router.get('**/*.js', async ctx => {26 const entry = join(PUBLIC_PATH, ctx.path)27 if (await fileExists(entry)) {28 const cache = ROLLUP_CACHE[entry]29 try {30 const bundle = await rollup({ cache, entry })31 const output = await bundle.generate(CONFIG)32 ROLLUP_CACHE[entry] = bundle33 ctx.body = output.code + '\n//# sourceMappingURL=' + output.map.toUrl()34 } catch (error) {35 ctx.body = `Rollup error:\n${error.stack}`36 }37 }38 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { rollup } from 'rollup';2import commonjs from 'rollup-plugin-commonjs';3import resolve from 'rollup-plugin-node-resolve';4import { uglify } from 'rollup-plugin-uglify';5import babel from 'rollup-plugin-babel';6import rollupCache from 'rollup-cache';7import { readFileSync, writeFileSync } from 'fs';8import { join } from 'path';9import { minify } from 'uglify-es';10import { version } from './package.json';11import { name } from './package.json';12import { author } from './package.json';13import { license } from './package.json';14import { description } from './package.json';15import { homepage } from './package.json';16import { bugs } from './package.json';17import { repository } from './package.json';18import { keywords } from './package.json';19import { contributors } from './package.json';20import { dependencies } from './package.json';21import { peerDependencies } from './package.json';22import { devDependencies } from './package.json';23import { main } from './package.json';24import { browser } from './package.json';25import {

Full Screen

Using AI Code Generation

copy

Full Screen

1import {rollup} from 'rollup';2import * as path from 'path';3import * as fs from 'fs';4const cache = new Map();5async function main() {6 const bundle = await rollup({7 cache: cache.get('input.js')8 });9 await bundle.write({10 });11 cache.set('input.js', bundle);12}13main();14import {foo} from './foo.js';15console.log(foo);16export const foo = 'foo';17'use strict';18var foo = 'foo';19console.log(foo);20import {rollup} from 'rollup';21import * as path from 'path';22import * as fs from 'fs';23const cache = new Map();24async function main() {25 const bundle = await rollup({26 cache: cache.get('input.js')27 });28 await bundle.write({29 });30 cache.set('input.js', bundle);31}32main();33import {foo} from './foo.js';34console.log(foo);35export const foo = 'foo';36'use strict';37var foo = 'foo';38console.log(foo);39import {rollup} from 'rollup';40import * as path from 'path';41import * as fs from 'fs';42const cache = new Map();43async function main() {44 const bundle = await rollup({45 cache: cache.get('input.js')46 });47 await bundle.write({

Full Screen

Using AI Code Generation

copy

Full Screen

1var oracledb = require('oracledb');2var dbConfig = require('./dbconfig.js');3oracledb.getConnection(4 {5 },6 function(err, connection)7 {8 if (err) { console.error(err.message); return; }9 connection.execute(10 "FROM ( " +11 " WHERE department_id IN (10, 20) " +12 function(err, result)13 {14 if (err) { console.error(err.message); return; }15 console.log(result.rows);16 });17 });

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful