"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; function _react() { const data = _interopRequireDefault(require("react")); _react = function _react() { return data; }; return data; } function _path() { const data = require("path"); _path = function _path() { return data; }; return data; } function _rimraf() { const data = _interopRequireDefault(require("rimraf")); _rimraf = function _rimraf() { return data; }; return data; } function _fs() { const data = require("fs"); _fs = function _fs() { return data; }; return data; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _default(opts = {}) { const dllDir = opts.dllDir, api = opts.api, include = opts.include, exclude = opts.exclude; const paths = api.paths, _resolveDeps = api._resolveDeps, _api$_ = api._, pullAll = _api$_.pullAll, uniq = _api$_.uniq, UmiError = api.UmiError, printUmiError = api.printUmiError; const pkgFile = (0, _path().join)(paths.cwd, 'package.json'); const pkg = (0, _fs().existsSync)(pkgFile) ? require(pkgFile) : {}; // eslint-disable-line const depNames = pullAll(uniq(Object.keys(pkg.dependencies || {}).concat(include || [])), exclude).filter(dep => { return dep !== 'umi' && !dep.startsWith('umi-plugin-') && !dep.startsWith('@types/'); }); const webpack = require(_resolveDeps('af-webpack/webpack')); const files = uniq([...depNames, 'umi/link', 'umi/dynamic', 'umi/navlink', 'umi/redirect', 'umi/router', 'umi/withRouter', 'umi/lib/renderRoutes', 'umi/lib/createHistory', 'react', 'react-dom', 'react-router-dom']).sort((a, b) => a > b ? 1 : -1); const filesInfoFile = (0, _path().join)(dllDir, 'filesInfo.json'); if ((0, _fs().existsSync)(filesInfoFile)) { if (JSON.parse((0, _fs().readFileSync)(filesInfoFile, 'utf-8')).join(', ') === files.join(', ')) { console.log(`[umi-plugin-dll] File list is equal, don't generate the dll file.`); return Promise.resolve(); } } const afWebpackOpts = api.applyPlugins('modifyAFWebpackOpts', { initialValue: { cwd: paths.cwd, disableBabelTransform: true, alias: {}, babel: {}, styleLoader: { base: 1000 } } }); const afWebpackConfig = require(_resolveDeps('af-webpack/getConfig')).default(afWebpackOpts); const webpackConfig = _objectSpread({}, afWebpackConfig, { entry: { umi: files }, output: { path: dllDir, filename: '[name].dll.js', library: '[name]', publicPath: api.webpackConfig.output.publicPath }, plugins: [...afWebpackConfig.plugins, ...api.webpackConfig.plugins.filter(plugin => { return plugin instanceof webpack.DefinePlugin; }), new webpack.DllPlugin({ path: (0, _path().join)(dllDir, '[name].json'), name: '[name]', context: paths.absSrcPath })], resolve: _objectSpread({}, afWebpackConfig.resolve, { alias: _objectSpread({}, afWebpackConfig.resolve.alias, {}, api.webpackConfig.resolve.alias) }) }); return new Promise((resolve, reject) => { console.log('Building dll...'); require(_resolveDeps('af-webpack/build')).default({ webpackConfig, onSuccess() { console.log('[umi-plugin-dll] Build dll done'); (0, _fs().writeFileSync)(filesInfoFile, JSON.stringify(files), 'utf-8'); resolve(); }, onFail({ err, stats }) { _rimraf().default.sync(dllDir); printUmiError(new UmiError({ message: err && err.message, context: { err, stats, dll: true } }), { detailsOnly: true }); reject(err); } }); }); }