Best JavaScript code snippet using storybook-root
bundle-package.ts
Source:bundle-package.ts
1import path, { resolve } from 'path';2import { bold, gray, greenBright } from 'chalk';3import execa from 'execa';4import { rollup, OutputOptions, watch, RollupOptions } from 'rollup';5import readPkgUp from 'read-pkg-up';6import fs from 'fs-extra';7import rollupTypescript from '@rollup/plugin-typescript';8import { nodeResolve } from '@rollup/plugin-node-resolve';9import commonjs from '@rollup/plugin-commonjs';10import json from '@rollup/plugin-json';11import { babel, getBabelOutputPlugin } from '@rollup/plugin-babel';12import { terser } from 'rollup-plugin-terser';13import { generateDtsBundle } from 'dts-bundle-generator';14import * as dtsLozalize from './dts-localize';15interface Options {16 input: string;17 externals: string[];18 cwd: string;19 optimized?: boolean;20 watch?: boolean;21}22async function build(options: Options) {23 const { input, externals, cwd, optimized } = options;24 const setting: RollupOptions = {25 input,26 external: externals,27 plugins: [28 nodeResolve({29 browser: true,30 preferBuiltins: true,31 }),32 commonjs(),33 babel({34 babelHelpers: 'external',35 skipPreflightCheck: true,36 }),37 json(),38 rollupTypescript({ lib: ['es2015', 'dom', 'esnext'], target: 'es6' }),39 ],40 };41 const outputs: OutputOptions[] = [42 {43 dir: resolve(cwd, './dist/modern'),44 format: 'es',45 sourcemap: optimized,46 preferConst: true,47 plugins: [48 getBabelOutputPlugin({49 presets: [50 [51 '@babel/preset-env',52 {53 shippedProposals: true,54 useBuiltIns: 'usage',55 corejs: '3',56 modules: false,57 targets: { chrome: '94' },58 },59 ],60 ],61 }),62 optimized ? terser({ output: { comments: false }, module: true }) : null,63 ].filter(Boolean),64 },65 {66 dir: resolve(cwd, './dist/esm'),67 format: 'es',68 sourcemap: optimized,69 plugins: [70 getBabelOutputPlugin({71 presets: [72 [73 '@babel/preset-env',74 {75 shippedProposals: true,76 useBuiltIns: 'usage',77 modules: false,78 corejs: '3',79 },80 ],81 ],82 }),83 optimized ? terser({ output: { comments: false }, module: true }) : null,84 ].filter(Boolean),85 },86 {87 dir: resolve(cwd, './dist/cjs'),88 format: 'commonjs',89 plugins: [90 getBabelOutputPlugin({91 presets: [92 [93 '@babel/preset-env',94 {95 shippedProposals: true,96 useBuiltIns: 'usage',97 corejs: '3',98 modules: false,99 targets: { node: '14' },100 },101 ],102 ],103 }),104 optimized ? terser({ output: { comments: false }, module: true }) : null,105 ].filter(Boolean),106 },107 ];108 if (options.watch) {109 const watcher = watch({ ...setting, output: outputs });110 watcher.on('change', (event) => {111 console.log(`${greenBright('changed')}: ${event.replace(path.resolve(cwd, '../..'), '.')}`);112 dts(options);113 });114 } else {115 const bundler = await rollup(setting);116 await Promise.all(outputs.map((config) => bundler.write(config)));117 await bundler.close();118 }119}120async function dts({ input, externals, cwd, ...options }: Options) {121 if (options.watch) {122 try {123 const [out] = await generateDtsBundle(124 [125 {126 filePath: input,127 output: { inlineDeclareGlobals: false, sortNodes: true, noBanner: true },128 },129 ],130 { followSymlinks: false }131 );132 await fs.outputFile('dist/ts3.9/index.d.ts', out);133 } catch (e) {134 console.log(e.message);135 }136 } else {137 const [out] = await generateDtsBundle(138 [139 {140 filePath: input,141 output: { inlineDeclareGlobals: false, sortNodes: true, noBanner: true },142 },143 ],144 { followSymlinks: false }145 );146 const bundledDTSfile = path.join(cwd, 'dist/ts-tmp/index.d.ts');147 const localizedDTSout = path.join(cwd, 'dist/ts3.9');148 await fs.outputFile(bundledDTSfile, out);149 await dtsLozalize.run([bundledDTSfile], localizedDTSout, { externals, cwd });150 // await fs.remove(path.join(cwd, 'dist/ts-tmp'));151 await execa('node', [152 path.join(__dirname, '../node_modules/.bin/downlevel-dts'),153 'dist/ts3.9',154 'dist/ts3.4',155 ]);156 }157}158async function removeDist() {159 await fs.remove('dist');160}161export async function run({ cwd, flags }: { cwd: string; flags: string[] }) {162 const { packageJson: pkg } = await readPkgUp({ cwd });163 const message = gray(`Built: ${bold(`${pkg.name}@${pkg.version}`)}`);164 console.time(message);165 if (flags.includes('--reset')) {166 await removeDist();167 }168 const input = path.join(cwd, pkg.bundlerEntrypoint);169 const externals = Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies });170 const options: Options = {171 cwd,172 externals,173 input,174 optimized: flags.includes('--optimized'),175 watch: flags.includes('--watch'),176 };177 await Promise.all([178 //179 build(options),180 dts(options),181 ]);182 console.timeEnd(message);...
Using AI Code Generation
1const { bundledDTSFile } = require('storybook-root');2module.exports = {3 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],4 typescript: {5 checkOptions: {},6 reactDocgenTypescriptOptions: {7 propFilter: (prop) => {8 if (prop.parent) {9 return !prop.parent.fileName.includes('node_modules');10 }11 return true;12 },13 },14 },15 core: {16 },17 async viteFinal(config) {18 config.resolve.alias = {19 };20 return config;21 },22};23import { addDecorator } from '@storybook/react';24import { withRoot } from 'storybook-root';25addDecorator(withRoot);
Using AI Code Generation
1import {bundledDTSfile} from 'storybook-root';2module.exports = {3 module: {4 {5 use: {6 options: {7 }8 }9 }10 }11};12If you are using storybook-root in a javascript project and you do not want to add the above to your webpack.config.js, then you can use the following code to import the bundledDTSfile method into your javascript project:13const storybookRoot = require('storybook-root');14const bundledDTSfile = storybookRoot.bundledDTSfile;
Using AI Code Generation
1const { bundledDTSFile } = require('storybook-root');2const { bundledDTSFile } = require('storybook-root');3const { bundledDTSFile } = require('storybook-root');4const { bundledDTSFile } = require('storybook-root');5const { bundledDTSFile } = require('storybook-root');6const { bundledDTSFile } = require('storybook-root');7const { bundledDTSFile } = require('storybook-root');8const { bundledDTSFile } = require('storybook-root');9const { bundledDTSFile } = require('storybook-root');10const { bundledDTSFile } = require('storybook-root');11const { bundledDTSFile } = require('storybook-root');12const { bundledDTSFile } = require('storybook-root');13const { bundledDTSFile } = require('storybook-root');14const { bundledDTSFile } = require('storybook-root');15const { bundledDTSFile } = require('storybook-root');16const { bundledDTSFile } = require('storybook-root');17const { bundledDTSFile } = require('storybook-root');18const { bundledDTSFile } = require('storybook-root');19const { bundledDTSFile } = require('storybook-root');
Using AI Code Generation
1import { bundledDTSFile } from 'storybook-root';2import { bundledDTSFile } from 'storybook-root';3import { bundledDTSFile } from 'storybook-root';4import { bundledDTSFile } from 'storybook-root';5import { bundledDTSFile } from 'storybook-root';6import { bundledDTSFile } from 'storybook-root';7import { bundledDTSFile } from 'storybook-root';8import { bundledDTSFile } from 'storybook-root';9import { bundledDTSFile } from 'storybook-root';10import
Using AI Code Generation
1require('storybook-root-require').bundledDTSfile('./test.d.ts');2declare module 'test' {3 export const test: string;4}5declare module 'test2' {6 export const test2: string;7}8require('storybook-root-require').bundledDTSfile('./test2.d.ts');9require('storybook-root-require').bundledDTSfile('./test3.d.ts');10declare module 'test3' {11 export const test3: string;12}13require('storybook-root-require').bundledDTSfile('./test3.d.ts');14declare module 'test4' {15 export const test4: string;16}17require('storybook-root-require').bundledDTSfile('./test4.d.ts');18declare module 'test5' {19 export const test5: string;20}21require('storybook-root-require').bundledDTSfile('./test5.d.ts');22declare module 'test6' {23 export const test6: string;24}25require('storybook-root-require').bundledDTSfile('./test6.d.ts');26declare module 'test7' {27 export const test7: string;28}29require('storybook-root-require').bundledDTSfile('./test7.d.ts');30declare module 'test8' {
Using AI Code Generation
1import { bundledDTSfile } from 'storybook-root';2console.log(bundledDTSfile());3import { bundledJSfile } from 'storybook-root';4console.log(bundledJSfile());5import { bundledJSfile } from 'storybook-root';6console.log(bundledJSfile());7import { bundledJSfile } from 'storybook-root';8console.log(bundledJSfile());9import { bundledJSfile } from 'storybook-root';10console.log(bundledJSfile());11import { bundledJSfile } from 'storybook-root';12console.log(bundledJSfile());13import { bundledJSfile } from 'storybook-root';14console.log(bundledJSfile());15import { bundledJSfile } from '
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!!