本文整理汇总了TypeScript中neutrino.Neutrino.use方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Neutrino.use方法的具体用法?TypeScript Neutrino.use怎么用?TypeScript Neutrino.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neutrino.Neutrino
的用法示例。
在下文中一共展示了Neutrino.use方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (neutrino: Neutrino) => {
// Add environment variables to bundle.
neutrino.use(env, getTuxEnv())
neutrino.use(targetEnv, neutrino.options.target)
neutrino.use(appEntryConstant, neutrino.options.appEntry)
}
示例2: default
export default (neutrino: Neutrino) => {
// Configure admin variable.
if (process.env.ADMIN == null) {
const { admin } = neutrino.options
const buildAdmin =
admin != null ? admin : process.env.NODE_ENV === 'development'
process.env.ADMIN = buildAdmin ? 'true' : ''
}
// Add ADMIN environment variable to bundle.
neutrino.config.plugin('env').tap(args => args.concat('ADMIN'))
// Prioritize `source.admin.js` over `source.js` in admin builds.
if (process.env.ADMIN) {
neutrino.use(adminExtension)
}
}
示例4: default
export default (neutrino: Neutrino, options: any = {}) => {
const pkg = getPackageJson(neutrino.options.root)
const sourceMap = !!(
(pkg.dependencies && pkg.dependencies['source-map-support']) ||
(pkg.devDependencies && pkg.devDependencies['source-map-support'])
)
neutrino.config.module
.rule('compile')
.use('babel')
.tap(existing =>
compile.merge(existing, {
plugins: [
...(options.polyfills.async
? [[require.resolve('fast-async'), { spec: true }]]
: []),
require.resolve('babel-plugin-dynamic-import-node'),
],
presets: [
[
'babel-preset-env',
{
debug: neutrino.options.debug,
targets: { node: '6.10' },
modules: false,
useBuiltIns: true,
exclude: options.polyfills.async
? ['transform-regenerator', 'transform-async-to-generator']
: [],
},
],
],
})
)
neutrino.use(webCompat)
// prettier-ignore
neutrino.config
.when(sourceMap, () => neutrino.use(banner))
.performance
.hints(false)
.end()
.target('node')
.node
.clear()
.set('__filename', false)
.set('__dirname', false)
.end()
.devtool('source-map')
.externals([nodeExternals({ whitelist: [/^webpack/, /tux/] })])
.entry('index')
.add(neutrino.options.mains.index)
.end()
.output
.path(neutrino.options.output)
.filename('[name].js')
.libraryTarget('commonjs2')
.chunkFilename('[id].[hash:5]-[chunkhash:7].js')
.end()
.when(neutrino.options.env.NODE_ENV === 'development', config => {
config.devtool('inline-source-map');
});
}
示例5:
.when(isDev, () => {
neutrino.use(hot)
neutrino.use(betterDev, options)
})
示例6: 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))
}
}