本文整理匯總了TypeScript中neutrino.Neutrino.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Neutrino.on方法的具體用法?TypeScript Neutrino.on怎麽用?TypeScript Neutrino.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類neutrino.Neutrino
的用法示例。
在下文中一共展示了Neutrino.on方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: default
export default (neutrino: Neutrino) => {
// Only write stats files during build. Dev server automatically
// has access to stats.
neutrino.on('prebuild', () =>
neutrino.config.plugin('stats').use(StatsWriterPlugin, [
{
fields: ['assetsByChunkName', 'chunks', 'publicPath', 'hash'],
},
])
)
}
示例2: default
export default (neutrino: Neutrino, opts: Partial<Options> = {}) => {
const isDev = process.env.NODE_ENV === 'development'
const options = merge<Options>(
{
hot: true,
polyfills: {
async: true,
},
html: {},
},
opts as Options
)
// This preset depends on a target option, let's give it a default.
neutrino.options.target = neutrino.options.target || 'browser'
const isServer = (neutrino.options.isServer =
neutrino.options.target === 'server')
// Replace entry based on target.
neutrino.options.appEntry = neutrino.options.mains.index
neutrino.options.mains.index = isServer
? neutrino.options.serverEntry
: neutrino.options.browserEntry
// Build on top of the offical react preset (overriding devServer and open functionality for our own in tux-scripts).
// Skip react-hot-loader for now while enabling other HMR functionality.
const reactOptions = merge<any>(options, {
devServer: { open: false },
hot: false,
...isServer ? { style: { extract: false } } : {},
})
neutrino.use(react, reactOptions)
// Switch to custom html plugin.
neutrino.use(html, options.html)
// Add more environment variables.
neutrino.use(env, options)
// Write stats files when building.
neutrino.use(stats)
// prettier-ignore
neutrino.config
// Webpack Hot Server Middleware expects a MultiConfiguration with "server" and "client" names.
.set('name', isServer ? 'server' : 'client')
// Remove devServer. We use webpack-dev-middleware for SSR support.
.devServer.clear().end()
// Neutrino defaults to relative paths './'. Tux is optimized for SPAs, where absolute paths
// are a better default.
.output
.publicPath('/')
.end()
// Fix svg imports: https://github.com/mozilla-neutrino/neutrino-dev/issues/272
.module
.rule('svg')
.use('url')
.loader(require.resolve('file-loader'))
.options({ limit: 8192 })
.end()
.end()
.end()
// Add goodies from create-react-app project.
.when(isDev, () => {
neutrino.use(hot)
neutrino.use(betterDev, options)
})
// Wait until all presets and middlewares have run before
// adapting the config for SSR.
if (isServer) {
neutrino.on('prerun', () => neutrino.use(ssr, options))
}
}