Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
apply(compiler) {
this.compiler = compiler;
this.outputPath = compiler.options.output.path;
this.compilerContext = join(compiler.context, 'src');
this._appending = [];
// 向 loader 中传递插件实例
loader.$applyPluginInstance(this);
// 使用模板插件,用于设置输出格式
new MiniTemplate(this).apply(compiler);
new ProgressPlugin({ handler: this.progress }).apply(compiler);
const resolver = ResolverFactory.createResolver(Object.assign({
fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
extensions: ['.js', '.json']
}, this.compiler.options.resolve));
this.resolver = (context, request) => {
return new Promise((resolve, reject) => {
resolver.resolve({}, context, request, {}, (err, res) => err ? reject(err) : resolve(res));
});
};
this.miniEntrys = utils.formatEntry(compiler.options.entry, this.chunkNames);
// 获取打包后路径(在 loader 中有使用)
this.getDistFilePath = () => {};
// hooks
this.compiler.hooks.environment.tap('MiniPlugin', this.setEnvHook.bind(this));
// node_modules/@types we need:
// - the inclusion of .d.ts to the extensions (see above)
// - an explicit inclusion of node_modules/@types to the spots
// to look for modules (in addition to "node_modules" which
// is the default for enhanced-resolve)
modules: ["node_modules", "node_modules/@types"]
};
const NON_OVERRIDABLE_RESOLVE_OPTIONS = {
// This should cover most of the bases of dependency-cruiser's
// uses. Not overridable for now because for other
// file systems it's not sure we can use sync system calls
// Also: passing a non-cached filesystem makes performance
// worse.
fileSystem: new enhancedResolve.CachedInputFileSystem(
new enhancedResolve.NodeJsInputFileSystem(),
CACHE_DURATION
),
// our code depends on sync behavior, so having this
// overriden is not an option
useSyncFileSystemCalls: true
};
function pushPlugin(pPlugins, pPluginToPush) {
return (pPlugins || []).concat(pPluginToPush);
}
function compileResolveOptions(pResolveOptions, pTSConfig) {
let lResolveOptions = {};
// TsConfigPathsPlugin requires a baseUrl to be present in the
// tsconfig, otherwise it prints scary messages that it didn't
'use strict'
const path = require('path')
const os = require('os')
const execFile = require('execa')
const webpack = require('webpack')
const minify = require('babel-minify')
const gzipSize = require('gzip-size')
const MemoryFs = require('memory-fs')
const Buffer = require('buffer').Buffer
const parsePackageName = require('parse-package-name')
const enhancedResolve = require('enhanced-resolve')
const tmp = path.join(os.tmpdir(), 'jsize-' + Math.random().toString(36).substring(7))
const npmBin = path.join(require.resolve('npm/package.json'), '../../.bin/npm')
const resolver = enhancedResolve.ResolverFactory.createResolver({
fileSystem: new enhancedResolve.NodeJsInputFileSystem(),
mainFields: ['browser', 'module', 'main']
})
require('fs').mkdirSync(tmp)
/**
* Calculates the sizes (initial, minified and gziped) for a given package.
*
* @param {string|string[]} pkgs - the package(s) to check the size of.
* @return {Promise}
*/
module.exports = function jsize (pkgs) {
// Parse all package details. (allows for single or multiple packages)
pkgs = [].concat(pkgs).map(parsePackageName)
// Get unique package ids.
const ids = pkgs
.map(it => it.name + '@' + (it.version || 'latest'))
import * as fse from 'fs-extra';
import * as upath from 'upath';
import chalk from 'chalk';
import { NodeJsInputFileSystem, ResolverFactory } from 'enhanced-resolve';
import * as UglifyJS from 'uglify-js';
import { Settings } from './Settings';
import { outputFileThenLog } from './CompilerUtilities';
import { Shout } from './Shout';
import { prettyHrTime } from './PrettyUnits';
let resolver = ResolverFactory.createResolver({
fileSystem: new NodeJsInputFileSystem(),
extensions: ['.js'],
mainFields: ['unpkg', 'browser', 'main']
});
/**
* Contains methods for concatenating JS files.
*/
export class ConcatBuildTool {
/**
* Gets the project settings.
*/
private readonly settings: Settings;
/**
* Gets the compiler build flags.
constructor(innerFS = new NodeJsInputFileSystem()) {
super(innerFS, CACHE_DURATION);
}
module.exports.createResolver = function (compiler) {
const resolver = ResolverFactory.createResolver(
Object.assign(
{
fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
extensions: ['.js', '.json']
},
compiler.options.resolve
)
)
return (context, request) => {
return new Promise((resolve, reject) => {
resolver.resolve({}, context, request, {}, (err, res) => err ? reject(err) : resolve(res))
})
}
}