本文整理汇总了TypeScript中webpack-node-externals.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: catch
isWorkspace = !!pkg.workspaces;
} catch (err) {
// no workspace
}
export const externalsNode = [
// require json files with nodes built-in require logic
function(_context: any, request: any, callback: any) {
if (/\.json$/.test(request)) {
callback(null, 'commonjs ' + request);
} else {
callback();
}
},
// default "node_modules" dir is excluded
WebpackNodeExternals()
];
if (isWorkspace) {
// ignore all modules in node_modules workspace root folder
externalsNode.push(
WebpackNodeExternals({
modulesDir: join(process.cwd(), '..', '..', 'node_modules')
})
);
}
export const externalsBrowser = [
(_context: any, request: any, callback: any) => {
// if it starts with a letter (and *not* a path like './', '../' or '/') we treat this module as external
// except 'mercateo/i18n'
示例2: resolve
import webpack from 'webpack'
import nodeExternals from 'webpack-node-externals'
import baseConfig from './base'
import { resolve } from './config'
const config: webpack.Configuration = {
...baseConfig,
entry: resolve('server/index.ts'),
target: 'node',
output: {
path: resolve('dist'),
filename: 'server.js',
libraryTarget: 'commonjs2',
},
externals: nodeExternals({
whitelist: [/\.css/],
}),
plugins: [
new webpack.DefinePlugin({
__SERVER__: true,
}),
],
}
export default config
示例3: 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');
});
}
示例4: function
};
export const devtool = 'cheap-module-inline-source-map';
export const devtoolProduction = 'source-map';
export const devtoolTest = 'inline-source-map';
export const externalsNode = [
// require json files with nodes built-in require logic
function(context, request, callback) {
if (/\.json$/.test(request)) {
callback(null, 'commonjs ' + request);
} else {
callback();
}
},
// in order to ignore all modules in node_modules folder
WebpackNodeExternals()
];
export const externalsBrowser = [
// by default we mark every `dependency` as external by setting `{ 'external-module': true }`
// see https://webpack.github.io/docs/configuration.html#externals
// after that we add custom externals defined in `project.ws.externals`
Object.assign(Object.keys(project.dependencies || {}).reduce((target, key) => {
target[key] = true;
return target;
}, {}), project.ws.externals)
];
示例5: default
export default ({
entry,
rules,
nodeExternalsOptions,
isUniversal,
useTypeScript,
tsLoaderType = TsLoaderType.Default,
tsconfig = paths.server.tsconfig,
}: ServerConfigOptions): Configuration => {
const { tsBaseRule, ...rest } = isUniversal ? universalDefaultRules : serverDefaultRules;
const preparedRules = useTypeScript
? {
tsRule: {
...tsBaseRule,
use: loaders.getTsLoader({ loaderType: tsLoaderType, forkedChecks: true, tsconfig }),
},
...rest,
}
: { ...rest };
const moduleRules = mergeAndReplaceRules(preparedRules, rules);
return webpackMerge(
commonConfig({
outputPath: paths.server.output.path,
outputPublicPath: appConfig.server.output.publicPath,
outputJsDir: '',
hash: false,
useTypeScript,
tsLoaderType,
tsconfig,
}),
{
name: appConfig.server.root,
target: 'node',
context: isUniversal ? paths.root : paths.server.sources,
entry,
resolve: {
modules: [isUniversal ? paths.client.sources : paths.server.sources],
alias: isUniversal
? {
server: paths.server.sources,
shared: paths.shared.sources,
client: paths.client.sources,
}
: undefined,
},
// http://jlongster.com/Backend-Apps-with-Webpack--Part-I
externals: webpackNodeExternals(nodeExternalsOptions),
stats: 'errors-only',
// stats: {
// colors: true,
// cached: false, // Add information about cached (not built) modules
// },
module: {
rules: Object.getOwnPropertyNames(moduleRules).map(name => moduleRules[name] || {}),
},
plugins: [
// Don't watch on client files when ssr is turned off because client by self make hot update
// and server not needs in updated files because server not render react components.
...(!isUniversal || appEnv.ssr ? [] : [new WatchIgnorePlugin([paths.client.root])]),
],
}
);
};
示例6: DefinePlugin
const createTaskConfig = (filePath: string): Configuration => {
const outFolder = path.resolve(`${paths.outputPath}tasks/${path.basename(path.dirname(filePath))}`);
return {
target: "node",
node:{
__dirname: false,
__filename: false
},
context: path.resolve(paths.sourceRoot),
entry: path.resolve(filePath),
plugins: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.EXTENSION_VERSION': JSON.stringify(process.env.EXTENSION_VERSION)
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
externals: [nodeExternals()],
resolve: {
plugins: [],
extensions: [ ".tsx", ".ts", ".js" ]
},
output:{
filename: 'index.js',
path: path.resolve(outFolder),
}
}
}
示例7: catch
} catch (err) {
// no workspace
}
export const externalsNode = [
// require json files with nodes built-in require logic
function(_context: any, request: any, callback: any) {
if (/\.json$/.test(request)) {
callback(null, 'commonjs ' + request);
} else {
callback();
}
},
// in order to ignore all modules in node_modules folder
WebpackNodeExternals({
modulesDir: isWorkspace ? join(process.cwd(), '..', '..') : undefined
})
];
export const externalsBrowser = [
(_context: any, request: any, callback: any) => {
// if it starts with a letter (and *not* a path like './', '../' or '/') we treat this module as external
// except 'mercateo/i18n'
if (/^[a-zA-Z]/.test(request) && !request.includes('mercateo/i18n')) {
callback(null, request);
} else {
callback();
}
},
...externalsSpa
];
示例8: join
},
// Currently cheap-module-source-map is broken https://github.com/webpack/webpack/issues/4176
devtool: 'source-map',
output: {
path: join(__dirname, 'dist'),
libraryTarget: 'commonjs',
filename: `${libraryName}.js`
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
handlebars: 'handlebars/dist/handlebars.min.js'
}
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader'
},
]
}
]
},
plugins: plugins,
target: 'node',
externals: [nodeExternals()],
}
示例9: nodePathReplacePlugin
loader: 'null-loader'
},
{
test: /\.(scss)$/,
exclude: [/node_modules/],
use: [{ loader: 'raw-loader' }, { loader: 'sass-loader' }]
},
{
test: /\.css$/,
use: ['raw-loader', 'css-loader'],
},
]
},
plugins: [
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
path.resolve(__dirname, '../src'),
{}
),
new nodePathReplacePlugin()
],
externals: [
nodeExternals()
],
performance: {
hints: false
}
};
示例10: Error
return new Promise<T>((resolve, reject) => {
// Load the Webpack config and make alterations needed for loading the output into Node
const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath);
webpackConfig.entry = modulePath;
webpackConfig.target = 'node';
// Make sure we preserve the 'path' and 'publicPath' config values if specified, as these
// can affect the build output (e.g., when using 'file' loader, the publicPath value gets
// set as a prefix on output paths).
webpackConfig.output = webpackConfig.output || {};
webpackConfig.output.path = webpackConfig.output.path || '/';
webpackConfig.output.filename = 'webpack-output.js';
webpackConfig.output.libraryTarget = 'commonjs';
const outputVirtualPath = path.join(webpackConfig.output.path, webpackConfig.output.filename);
// In Node, we want any JavaScript modules under /node_modules/ to be loaded natively and not bundled into the
// output (partly because it's faster, but also because otherwise there'd be different instances of modules
// depending on how they were loaded, which could lead to errors).
// ---
// NOTE: We have to use webpack-node-externals rather than webpack-externals-plugin because
// webpack-externals-plugin doesn't correctly resolve relative paths, which means you can't
// use css-loader, since tries to require('./../../node_modules/css-loader/lib/css-base.js') (see #132)
// ---
// So, ensure that webpackConfig.externals is an array, and push WebpackNodeExternals into it:
let externalsArray: any[] = (webpackConfig.externals as any[]) || [];
if (!(externalsArray instanceof Array)) {
externalsArray = [externalsArray];
}
webpackConfig.externals = externalsArray;
externalsArray.push(nodeExternals({
// However, we do *not* want to treat non-JS files under /node_modules/ as externals (i.e., things
// that should be loaded via regular CommonJS 'require' statements). For example, if you reference
// a .css file inside an NPM module (e.g., require('somepackage/somefile.css')), then we do need to
// load that via Webpack rather than as a regular CommonJS module.
//
// So, configure webpack-externals-plugin to 'whitelist' (i.e., not treat as external) any file
// that has an extension other than .js. Also, since some libraries such as font-awesome refer to
// their own files with cache-busting querystrings (e.g., (url('./something.css?v=4.1.2'))), we
// need to treat '?' as an alternative 'end of filename' marker.
//
// The complex, awkward regex can be eliminated once webpack-externals-plugin merges
// https://github.com/liady/webpack-node-externals/pull/12
//
// This regex looks for at least one dot character that is *not* followed by "js<end-or-questionmark>", but
// is followed by some series of non-dot characters followed by <end-or-questionmark>:
whitelist: [/\.(?!js(\?|$))([^.]+(\?|$))/]
}));
// The CommonsChunkPlugin is not compatible with a CommonJS environment like Node, nor is it needed in that case
const ChunkPlugin = webpack.optimize['CommonsChunkPlugin'];
if (ChunkPlugin !== undefined) {
webpackConfig.plugins = webpackConfig.plugins.filter(plugin => {
return !(plugin instanceof ChunkPlugin);
});
}
// The typical use case for DllReferencePlugin is for referencing vendor modules. In a Node
// environment, it doesn't make sense to load them from a DLL bundle, nor would that even
// work, because then you'd get different module instances depending on whether a module
// was referenced via a normal CommonJS 'require' or via Webpack. So just remove any
// DllReferencePlugin from the config.
// If someone wanted to load their own DLL modules (not an NPM module) via DllReferencePlugin,
// that scenario is not supported today. We would have to add some extra option to the
// asp-prerender tag helper to let you specify a list of DLL bundles that should be evaluated
// in this context. But even then you'd need special DLL builds for the Node environment so that
// external dependencies were fetched via CommonJS requires, so it's unclear how that could work.
// The ultimate escape hatch here is just prebuilding your code as part of the application build
// and *not* using asp-prerender-webpack-config at all, then you can do anything you want.
webpackConfig.plugins = webpackConfig.plugins.filter(plugin => {
// DllReferencePlugin is missing from webpack.d.ts for some reason, hence referencing it
// as a key-value object property
return !(plugin instanceof webpack['DllReferencePlugin']);
});
// Create a compiler instance that stores its output in memory, then load its output
const compiler = webpack(webpackConfig);
compiler.outputFileSystem = new MemoryFS();
compiler.run((err, stats) => {
if (err) {
reject(err);
} else {
// We're in a callback, so need an explicit try/catch to propagate any errors up the promise chain
try {
if (stats.hasErrors()) {
throw new Error('Webpack compilation reported errors. Compiler output follows: '
+ stats.toString({ chunks: false }));
}
// The dynamically-built module will only appear in node-inspector if it has some nonempty
// file path. The following value is arbitrary (since there's no real compiled file on disk)
// but is sufficient to enable debugging.
const fakeModulePath = setExtension(modulePath, '.js');
const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8');
const moduleInstance = requireFromString<T>(fileContent, fakeModulePath);
resolve(moduleInstance);
} catch(ex) {
reject(ex);
}
}
//.........这里部分代码省略.........