本文整理汇总了TypeScript中webpack.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dev
function dev(name: string, callback: () => void) {
//var filename = name.split('/')[1].substr(0, 3) + '-' + name.split('/')[1].substr(3) + '.js'
var filename = _.kebabCase(name.split('/')[1]) + '.js'
var options: any = {
entry: './' + name + '.js',
output: {
path: path.join(__dirname, '../../../public/assets/js'),
publicPath: "/assets/",
filename: "bundle.js"
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.js']
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.less$/, exclude: /node_modules/, loader: 'style!css!less' }
]
},
devtool: "sourcemap",
debug: true
}
var port = 7070
var compiler = webpack(options)
return new WebpackDevServer(compiler, {
stats: {
colors: true
},
historyApiFallback: true
}).listen(port, "localhost", function(err) {
if (err) throw err
callback()
})
}
示例2: webpackDevServer
export async function webpackDevServer(): Promise<void> {
const compiler = createWebpackCompiler(webpackConfig)
const server = new WebpackDevServer(compiler as any, {
publicPath: '/.assets/',
contentBase: './ui/assets',
stats: WEBPACK_STATS_OPTIONS,
noInfo: false,
proxy: {
'/': {
target: 'http://localhost:3081',
ws: true,
// Avoid crashing on "read ECONNRESET".
onError: err => console.error(err),
onProxyReqWs: (_proxyReq, _req, socket) =>
socket.on('error', err => console.error('WebSocket proxy error:', err)),
},
},
})
return new Promise<void>((resolve, reject) => {
server.listen(3080, '127.0.0.1', (err?: Error) => {
if (err) {
reject(err)
} else {
resolve()
}
})
})
}
示例3: Promise
run: function(runTaskOptions: ServeTaskOptions) {
var project = this.cliProject;
rimraf.sync(path.resolve(project.root, runTaskOptions.outputPath));
const config = new NgCliWebpackConfig(project, runTaskOptions.environment).config;
const webpackCompiler = webpack(config);
webpackCompiler.apply(new ProgressPlugin({
profile: true
}));
return new Promise( (resolve, reject) => {
webpackCompiler.watch({}, (err, stats) => {
if (err) {
lastHash = null;
console.error(err.stack || err);
if(err.details) console.error(err.details);
reject(err.details);
}
if(stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
}
})
})
}
示例4: Promise
it('bundleable by webpack with no errors', async function() {
this.timeout(50000);
const memoryFS = new MemoryFS();
const rootPath = await pkgDir(__dirname);
const compiler = webpack({
mode: 'development',
entry: {
main: path.join(rootPath!, 'dist', 'src', 'lib', 'service.js')
},
node: {
path: 'empty', // users should provide alias to path-webpack
net: 'empty',
fs: 'empty',
module: 'empty'
}
});
compiler.outputFileSystem = memoryFS;
await new Promise((res, rej) =>
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
rej(err || new Error(stats.toString()));
} else {
res();
}
})
);
});
示例5: compiler
private compiler(): Property<webpack.Compiler, Error> {
try {
return Kefir.constant(webpack(this.config));
} catch (e) {
return Kefir.constantError(e);
}
}
示例6: Promise
run: function(runTaskOptions: ServeTaskOptions) {
var project = this.cliProject;
rimraf.sync(path.resolve(project.root, runTaskOptions.outputPath));
var config = new NgCliWebpackConfig(project, runTaskOptions.environment).config;
const webpackCompiler = webpack(config);
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
webpackCompiler.apply(new ProgressPlugin({
profile: true
}));
return new Promise((resolve, reject) => {
webpackCompiler.run((err, stats) => {
// Don't keep cache
// TODO: Make conditional if using --watch
webpackCompiler.purgeInputFileSystem();
if(err) {
lastHash = null;
console.error(err.stack || err);
if(err.details) console.error(err.details);
reject(err.details);
}
if(stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(webpackOutputOptions) + "\n");
}
resolve();
});
});
}
示例7: webpack
export const bundle = (entry: any, output: string, tsconfig?: string, outputDir?: string, watch?: boolean, minify?: boolean, callback?: any) => {
const webpackConfig = Object.assign<{[index: string]: any}, typeof config>({}, config)
const plugins = []
if (minify) {
plugins.push(new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$super', '$', 'exports', 'require']
},
compress: {
warnings: false
}
}))
delete webpackConfig.devtool
}
if (tsconfig) {
webpackConfig.ts.configFileName = tsconfig
}
webpackConfig.entry = entry
webpackConfig.plugins = plugins
webpackConfig.output.path = path.join(process.cwd(), outputDir || 'dist')
webpackConfig.output.filename = output
webpackConfig.watch = watch
return webpack(webpackConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack', err)
}
gutil.log('[webpack]', stats.toString())
callback()
})
}
示例8: startPublications
export function startPublications() {
const mode = process.env.NODE_ENV || "DEVELOPMENT";
const app = express();
if (mode.toUpperCase() === "DEVELOPMENT") {
const compiler = webpack(webpackConfig as webpack.Configuration);
app.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
})
);
app.use(webpackHotMiddleware(compiler));
app.use("/playground", graphqlPlayground({ endpoint: "/graphql" }));
} else {
const publicPath = path.resolve(__dirname, "../public");
app.use(express.static(publicPath));
app.get("*", (req, res) =>
res.sendFile(path.resolve(publicPath, "index.html"))
);
}
app.use(jwt(jwtConfig));
app.use(
"/graphql",
graphqlHttp(request => ({
schema,
context: { user: request.user },
}))
);
app.use(onAuthError);
app.get("/documents/:id/pdf", documentPdfHandler);
app.listen(PORT, () => {
console.log(`Publications started on port ${PORT}.`);
});
}
示例9: Promise
export function build<T>(config: T) {
const compiler = webpack(config)
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) {
return reject(err)
}
const messages = formatWebpackMessages(stats.toJson())
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1
}
return reject(new Error(messages.errors.join('\n\n')))
}
return resolve({
stats,
warnings: messages.warnings,
})
})
})
}
示例10: WebpackDevServer
export = () => {
let options = {
contentBase: 'dist/dev',
colors: true,
progress: true,
watch: true,
stats: {
colors: true,
progress: true
}
};
new WebpackDevServer(webpack(config), options)
.listen(
config.devServer.port,
config.devServer.host,
(err: any) => {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
// Server listening
gutil.log(
"[webpack-dev-server]",
"http://" + config.devServer.host + ":" + config.devServer.port + "/webpack-dev-server/index.html");
// keep the server alive or continue?
// callback();
});
};