Best JavaScript code snippet using storybook-root
gulpfile.js
Source: gulpfile.js
1const gulp = require('gulp'),2 browserSync = require('browser-sync'),3 livereload = require('gulp-livereload'),4 sourcemaps = require('gulp-sourcemaps'),5 del = require('del'),6 webpack = require('webpack-stream'),7 gulpif = require('gulp-if'),8 VueLoaderPlugin = require('vue-loader/lib/plugin')9/* === ÐÑаÑивое оÑобÑажение оÑибок === */10const notify = require('gulp-notify')11function emit_end(err) {12 this.emit('end')13}14/* --- ÐÑаÑивое оÑобÑажение оÑибок --- */15/* === Ð¤Ð°Ð¹Ð»Ñ Ð¿ÑоекÑа === */16const conf = {17 src: './app',18 dest: './build',19 dest_assets: './build/assets'20}21const html_files = [22 conf.src + '/**/*.html',23]24const js_files = [25 '!' + conf.src + '/**/*.map',26 conf.src + '/**/*.js',27 conf.src + '/*.js',28 conf.src + '/**/*.vue',29 conf.src + '/*.vue'30]31const assets_files = [32 conf.src + '/assets/**/*.*'33]34var isDev = false // ÐÑод35// let isDev = true // Ðев36var isProd = !isDev37var webpack_config = {38 output: {39 filename: 'main.js'40 },41 module: {42 rules: [{43 test: /\.txt$|\.png$|\.jpg$|\.jpeg$|\.svg$/i,44 use: [{45 loader: 'url-loader',46 options: {47 fallback: 'file-loader',48 },49 }, ],50 },51 {52 test: /\.js$/,53 loader: 'babel-loader',54 exclude: '/node_modules/'55 },56 {57 test: /\.vue$/,58 loader: 'vue-loader',59 options: {60 hotReload: false61 }62 },63 {64 test: /\.css$/,65 use: [66 'vue-style-loader',67 'css-loader'68 ]69 },70 {71 test: /\.scss$/,72 use: [73 'vue-style-loader',74 'css-loader',75 'sass-loader'76 ]77 },78 {79 test: /\.sass$/,80 use: [81 'vue-style-loader',82 'css-loader',83 {84 loader: 'sass-loader',85 options: {86 indentedSyntax: true87 }88 }89 ]90 }91 ]92 },93 plugins: [94 new VueLoaderPlugin()95 ],96 mode: isDev ? 'development' : 'production',97 devtool: isDev ? 'eval-source-map' : 'none',98}99/* --- Ð¤Ð°Ð¹Ð»Ñ Ð¿ÑоекÑа --- */100// ÐолÑзоваÑелÑÑкие ÑкÑипÑÑ Ð¿ÑоекÑа101function browser_sync() {102 browserSync({103 server: {104 baseDir: conf.dest // './build'105 },106 notify: false,107 open: false,108 reloadOnRestart: true,109 cors: true,110 })111}112function js() {113 return gulp.src(conf.src + '/main.js')114 .pipe(webpack(webpack_config).on("error", notify.onError(function(error) {115 return "Error webpack: " + error.message;116 })).on('error', emit_end))117 .pipe(gulpif(isDev, sourcemaps.init({ loadMaps: true })))118 .pipe(gulpif(isDev, gulp.dest(conf.dest)))119 .pipe(gulpif(isProd, gulp.dest(conf.dest)))120 .pipe(gulpif(isDev, sourcemaps.write(conf.dest)))121 .pipe(browserSync.reload({ stream: true }))122 .pipe(livereload())123}124function html() {125 return gulp.src(html_files)126 .pipe(gulp.dest(conf.dest))127 .pipe(browserSync.reload({ stream: true }))128 .pipe(livereload())129}130gulp.task('watch', ['setDev', 'build', 'browser_sync'], function() {131 livereload.listen()132 gulp.watch(html_files, ['html'])133 gulp.watch(js_files, ['js'])134})135gulp.task('build', ['removedist', 'livereload2build', 'js'], function() {136 // return gulp.src(assets_files)137 // .pipe(gulp.dest(conf.dest_assets))138})139function livereload2build() {140 if (isDev) {141 return gulp.src([142 conf.src + '/livereload.js',143 conf.src + '/index.html',144 ])145 .pipe(gulp.dest(conf.dest))146 }147}148function removedist() {149 try {150 return del.sync(conf.dest)151 } catch (err) {}152}153function setDev() {154 isDev = true155 isProd = false156 webpack_config.mode = isDev ? 'development' : 'production'157 webpack_config.devtool = isDev ? 'eval-source-map' : 'none'158}159gulp.task('browser_sync', browser_sync)160gulp.task('js', js)161gulp.task('html', html)162gulp.task('removedist', removedist)163gulp.task('livereload2build', livereload2build)164gulp.task('setDev', setDev)...
prebuild.ts
Source: prebuild.ts
1import cFs from 'fs';2import path from 'path';3const fs = cFs.promises;4const dist = path.resolve(__dirname, '..', 'dist');5async function removeDist(pth: string) {6 const files = await fs.readdir(pth);7 for (let file of files) {8 if ((await fs.stat(path.resolve(pth, file))).isFile()) {9 await fs.unlink(path.resolve(pth, file));10 } else {11 await removeDist(path.resolve(pth, file));12 }13 }14 await fs.rmdir(pth);15}...
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.
The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!