本文整理汇总了TypeScript中browserify类的典型用法代码示例。如果您正苦于以下问题:TypeScript browserify类的具体用法?TypeScript browserify怎么用?TypeScript browserify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了browserify类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Browserify
export default function Browserify() {
let smildSettings = helper.getSettings(),
browserifySettings = {
entries: [getBootstrapperPath()],
basedir: process.cwd(),
debug: !helper.isRelease(),
cache: {},
packageCache: {},
fullPaths: true
},
bundleStream = helper.isWatching() ? watchify(browserify(browserifySettings), {
poll: /^win/.test(process.platform)
}) : browserify(browserifySettings);
bundleStream = bundleStream.plugin(tsify, {
project: new TypescriptSettingsParser().parse(),
typescript: require(smildSettings.typescriptPath)
});
if (helper.isWatching())
bundleStream.on('update', () => rebundleDevelopment(bundleStream));
function getBootstrapperPath() {
let target = helper.getCurrentTarget();
return path.resolve(smildSettings.targets, target, 'bootstrapper.ts');
}
function rebundleDevelopment(bundleStream) {
let bundle = bundleStream.bundle();
if (buildHelper.isWatching())
bundle = bundle.on('error', function (err) {
console.error(err.message);
this.emit("end");
});
return bundle
.pipe(source('main.js'))
.pipe(transform(() => {
return exorcist(helper.getTempFolder() + '/js/main.map.js');
}))
.pipe(gulp.dest(helper.getTempFolder() + '/js'))
.pipe(refresh({
start: helper.isWatching(),
port: smildSettings.liveReloadPort
}));
}
function rebundleRelease(bundleStream) {
return bundleStream.bundle()
.pipe(source('main.js'))
.pipe(streamify(uglify(smildSettings.uglifyjs)))
.pipe(buffer())
.pipe(gulp.dest(helper.getTempFolder() + '/js'));
}
return helper.isRelease() ? rebundleRelease(bundleStream) : rebundleDevelopment(bundleStream);
}
示例2: bundleCasesFrom
function bundleCasesFrom(i: number) {
if (i >= cases.length) return;
const b = browserify();
b.ignore("tape");
b.add(`${__dirname}/${cases[i]}.js`);
b.transform(path.normalize(__dirname + "/../cwise.js"));
tape(cases[i], (t) => { // Without nested tests, the asynchronous nature of bundle causes issues with tape...
b.bundle((err, src) => {
if (err) {
throw new Error("failed to bundle!");
}
vm.runInNewContext(src.toString(), {
test: t.test.bind(t),
Buffer,
Int8Array,
Int16Array,
Int32Array,
Float32Array,
Float64Array,
Uint8Array,
Uint16Array,
Uint32Array,
Uint8ClampedArray,
console: { log: console.log.bind(console) }
});
t.end();
});
});
bundleCasesFrom(i + 1);
}
示例3: build
export function build(srcPath: string, destPath: string, cb: Function){
const tempPath = $path(process.cwd(), './temp/ts');
const builder = new Builder({
destPath,
srcPath,
tempPath
});
const meta = builder.buildSubs('.');
const compSet: IComponentSet = {
name: null,
items: meta
};
const includeCode = genIncludeFile(compSet, srcPath, tempPath);
const includeFilePath = $path(tempPath, './include.ts');
fs.writeFileSync(includeFilePath, includeCode);
const brofy = browserify({
debug: true
});
brofy
.add(includeFilePath)
.external([
"fg-js/build/client/main"
])
.plugin(tsify, {
project: buildCfg
})
.bundle(function(err: any, code: Buffer){
if (err){
console.error(err);
return;
};
fs.writeFileSync(destPath, code);
cb(null);
});
};
示例4: getBrowserCodeStream
export function getBrowserCodeStream(appName: string, opts?: PrebootOptions): any {
opts = normalize(opts);
let bOpts = {
entries: [__dirname + '/../browser/preboot_browser.js'],
standalone: 'preboot',
basedir: __dirname + '/../browser',
browserField: false
};
let b = browserify(bOpts);
// ignore any strategies that are not being used
ignoreUnusedStrategies(b, bOpts, opts.listen, listenStrategies, './listen/listen_by_');
ignoreUnusedStrategies(b, bOpts, opts.replay, replayStrategies, './replay/replay_after_');
if (opts.freeze) {
ignoreUnusedStrategies(b, bOpts, [opts.freeze], freezeStrategies, './freeze/freeze_with_');
}
// ignore other code not being used
if (!opts.buffer) { b.ignore('./buffer_manager.js', bOpts); }
if (!opts.debug) { b.ignore('./log.js', bOpts); }
// use gulp to get the stream with the custom preboot browser code
let outputStream = b.bundle()
.pipe(source('src/browser/preboot_browser.js'))
.pipe(buffer())
.pipe(insert.append('\n\n;preboot.init("' + appName + '",' + stringifyWithFunctions(opts) + ');\n\n'))
.pipe(insert.append('\n\n;preboot.init("' + appName + '2",' + stringifyWithFunctions(opts) + ');\n\n'))
.pipe(rename('preboot.js'));
// uglify if the option is passed in
return opts.uglify ? outputStream.pipe(uglify()) : outputStream;
}
示例5: builderjs
function builderjs(src: string[], dest: string, fWatch:boolean, fMinify: boolean, externals: string[], requires: string[]) {
var bundler = browserify({
basedir: '.',
debug: true,
entries: src,
cache: {},
packageCache: {}
})
.plugin(tsify, tsoptions.compilerOptions)
.external(externals);
bundler = requires.reduce((b, id) => bundler.require(resolve.sync(id), {expose: id}), bundler);
function rebundle() {
return bundler
.bundle()
.on('error', function(er:any)
{
console.log(er.message);
this.emit('end');
})
.pipe(source(dest))
.pipe(gulp.dest(paths.dest));
}
if (fWatch) {
bundler = watchify(bundler);
bundler.on("update", rebundle);
bundler.on("log", gutil.log);
gulp.watch('src/**/*.json', [])
.on("change", rebundle);
}
return rebundle();
}
示例6: return
return (next: (arg?: any) => void) => {
if (argv.verbose) gutil.log(`Building ${plugin_name}`)
const pluginOpts = {
entries: [path.resolve(path.join(paths.buildDir.jsTree, main))],
extensions: [".js"],
debug: true,
preludePath: pluginPreludePath,
prelude: pluginPreludeText,
paths: ['./node_modules', paths.buildDir.jsTree],
}
const plugin = browserify(pluginOpts)
labels[plugin_name] = namedLabeler(plugin, labels.bokehjs)
for (const file in labels.bokehjs) {
const name = labels.bokehjs[file]
if (name !== "_process")
plugin.external(file)
}
plugin
.bundle()
.pipe(source((paths.coffee as any)[plugin_name].destination.full))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// This solves a conflict when requirejs is loaded on the page. Backbone
// looks for `define` before looking for `module.exports`, which eats up
// our backbone.
.pipe(change((content: string) => {
return `(function() { var define = undefined; return ${content} })()`
}))
.pipe(insert.append(license))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.buildDir.js))
.on('end', () => next())
}
示例7: browserify
const tasks = files.map((entry: string) => {
return browserify({ entries: [entry] })
.bundle()
.pipe(source(entry.replace('tmp', 'resources')))
.pipe(buffer())
.pipe(uglify())
.pipe(dest('./built'));
});
示例8: Promise
return new Promise((resolve, reject) => {
let b = browserify({basedir: cwd, debug: debug});
b.require(requireable);
b.add(toAdd);
b.transform(babelify, {presets: require('babel-preset-es2015')});
b.bundle((err, res) => {
if (err) return reject(err);
return resolve(res.toString())
})
});
示例9: bundleApp
function bundleApp() {
return browserify(join(TMP_DIR, 'main'))
.bundle()
.pipe(require('vinyl-source-stream')(JS_PROD_APP_BUNDLE))
.pipe(require('vinyl-buffer')())
.pipe(plugins.uglify({
mangle: false
}))
.pipe(gulp.dest(JS_DEST));
}
示例10: browserify
let bundleApp = () => {
return browserify(join(TMP_DIR, 'main'))
.bundle()
.pipe(vinylSourceStream(JS_PROD_APP_BUNDLE))
.pipe(vinylBuffer())
// Strip comments and sourcemaps
.pipe(plugins.uglify({
mangle: true,
compress: true,
preserveComments: 'license'
}))
.pipe(gulp.dest(JS_DEST));
};