react-cosmos 5.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/bin/cosmos-export.js +14 -0
- package/bin/cosmos-native.js +14 -0
- package/bin/cosmos.js +18 -0
- package/config.schema.json +186 -0
- package/dist/config/createCosmosConfig.d.ts +2 -0
- package/dist/config/createCosmosConfig.js +133 -0
- package/dist/config/detectCosmosConfig.d.ts +2 -0
- package/dist/config/detectCosmosConfig.js +57 -0
- package/dist/config/getCosmosConfigAtPath.d.ts +1 -0
- package/dist/config/getCosmosConfigAtPath.js +28 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +51 -0
- package/dist/config/resolve.d.ts +1 -0
- package/dist/config/resolve.js +20 -0
- package/dist/config/shared.d.ts +29 -0
- package/dist/config/shared.js +17 -0
- package/dist/dom/DomFixtureLoader.d.ts +8 -0
- package/dist/dom/DomFixtureLoader.js +38 -0
- package/dist/dom/ErrorCatch.d.ts +15 -0
- package/dist/dom/ErrorCatch.js +117 -0
- package/dist/dom/container.d.ts +1 -0
- package/dist/dom/container.js +32 -0
- package/dist/dom/globalErrorHandler.d.ts +1 -0
- package/dist/dom/globalErrorHandler.js +14 -0
- package/dist/dom/index.d.ts +13 -0
- package/dist/dom/index.js +47 -0
- package/dist/dom/renderMessage.d.ts +3 -0
- package/dist/dom/renderMessage.js +30 -0
- package/dist/dom/rendererConnect.d.ts +1 -0
- package/dist/dom/rendererConnect.js +18 -0
- package/dist/dom/rendererId.d.ts +1 -0
- package/dist/dom/rendererId.js +26 -0
- package/dist/dom/selectedFixtureId.d.ts +2 -0
- package/dist/dom/selectedFixtureId.js +41 -0
- package/dist/dom/shared.d.ts +1 -0
- package/dist/dom/shared.js +14 -0
- package/dist/fixture.d.ts +1 -0
- package/dist/fixture.js +31 -0
- package/dist/getFixtureUrls.d.ts +8 -0
- package/dist/getFixtureUrls.js +98 -0
- package/dist/getFixtures.d.ts +13 -0
- package/dist/getFixtures.js +90 -0
- package/dist/getFixtures2.d.ts +14 -0
- package/dist/getFixtures2.js +117 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +67 -0
- package/dist/native.d.ts +9 -0
- package/dist/native.js +69 -0
- package/dist/nativeServer.d.ts +1 -0
- package/dist/nativeServer.js +39 -0
- package/dist/plugins/httpProxy.d.ts +2 -0
- package/dist/plugins/httpProxy.js +31 -0
- package/dist/plugins/openFile.d.ts +2 -0
- package/dist/plugins/openFile.js +87 -0
- package/dist/plugins/userDepsFile.d.ts +2 -0
- package/dist/plugins/userDepsFile.js +164 -0
- package/dist/plugins/webpack/client/errorOverlay/index.d.ts +1 -0
- package/dist/plugins/webpack/client/errorOverlay/index.js +16 -0
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.d.ts +2 -0
- package/dist/plugins/webpack/client/errorOverlay/reactErrorOverlay.js +63 -0
- package/dist/plugins/webpack/client/hmrErrorHandler.d.ts +1 -0
- package/dist/plugins/webpack/client/hmrErrorHandler.js +16 -0
- package/dist/plugins/webpack/client/index.d.ts +6 -0
- package/dist/plugins/webpack/client/index.js +43 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.d.ts +0 -0
- package/dist/plugins/webpack/client/reactDevtoolsHook.js +19 -0
- package/dist/plugins/webpack/client/userDeps.d.ts +5 -0
- package/dist/plugins/webpack/client/userDeps.js +15 -0
- package/dist/plugins/webpack/cosmosConfig/dom.d.ts +6 -0
- package/dist/plugins/webpack/cosmosConfig/dom.js +19 -0
- package/dist/plugins/webpack/cosmosConfig/webpack.d.ts +9 -0
- package/dist/plugins/webpack/cosmosConfig/webpack.js +88 -0
- package/dist/plugins/webpack/devServer.d.ts +2 -0
- package/dist/plugins/webpack/devServer.js +168 -0
- package/dist/plugins/webpack/export.d.ts +2 -0
- package/dist/plugins/webpack/export.js +135 -0
- package/dist/plugins/webpack/index.d.ts +2 -0
- package/dist/plugins/webpack/index.js +21 -0
- package/dist/plugins/webpack/shared.d.ts +2 -0
- package/dist/plugins/webpack/shared.js +22 -0
- package/dist/plugins/webpack/webpackConfig/default.d.ts +2 -0
- package/dist/plugins/webpack/webpackConfig/default.js +152 -0
- package/dist/plugins/webpack/webpackConfig/devServer.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/devServer.js +144 -0
- package/dist/plugins/webpack/webpackConfig/export.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/export.js +110 -0
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.d.ts +16 -0
- package/dist/plugins/webpack/webpackConfig/htmlPlugin.js +80 -0
- package/dist/plugins/webpack/webpackConfig/index.d.ts +2 -0
- package/dist/plugins/webpack/webpackConfig/index.js +21 -0
- package/dist/plugins/webpack/webpackConfig/module.d.ts +3 -0
- package/dist/plugins/webpack/webpackConfig/module.js +18 -0
- package/dist/plugins/webpack/webpackConfig/shared.d.ts +11 -0
- package/dist/plugins/webpack/webpackConfig/shared.js +254 -0
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.d.ts +1 -0
- package/dist/plugins/webpack/webpackConfig/userDepsLoader.js +36 -0
- package/dist/shared/cli.d.ts +5 -0
- package/dist/shared/cli.js +14 -0
- package/dist/shared/devServer/app.d.ts +5 -0
- package/dist/shared/devServer/app.js +51 -0
- package/dist/shared/devServer/httpServer.d.ts +11 -0
- package/dist/shared/devServer/httpServer.js +183 -0
- package/dist/shared/devServer/index.d.ts +18 -0
- package/dist/shared/devServer/index.js +209 -0
- package/dist/shared/devServer/messageHandler.d.ts +7 -0
- package/dist/shared/devServer/messageHandler.js +42 -0
- package/dist/shared/export.d.ts +6 -0
- package/dist/shared/export.js +137 -0
- package/dist/shared/fs.d.ts +4 -0
- package/dist/shared/fs.js +37 -0
- package/dist/shared/playgroundHtml.d.ts +6 -0
- package/dist/shared/playgroundHtml.js +116 -0
- package/dist/shared/pluginConfigs.d.ts +2 -0
- package/dist/shared/pluginConfigs.js +15 -0
- package/dist/shared/rendererConfig.d.ts +6 -0
- package/dist/shared/rendererConfig.js +5 -0
- package/dist/shared/shared.d.ts +6 -0
- package/dist/shared/shared.js +22 -0
- package/dist/shared/static/favicon.ico +0 -0
- package/dist/shared/static/index.html +19 -0
- package/dist/shared/static.d.ts +3 -0
- package/dist/shared/static.js +30 -0
- package/dist/shared/userDeps/findUserModulePaths.d.ts +11 -0
- package/dist/shared/userDeps/findUserModulePaths.js +45 -0
- package/dist/shared/userDeps/generateUserDepsModule.d.ts +9 -0
- package/dist/shared/userDeps/generateUserDepsModule.js +37 -0
- package/dist/shared/userDeps/getUserModules.d.ts +8 -0
- package/dist/shared/userDeps/getUserModules.js +45 -0
- package/dist/shared/userDeps/index.d.ts +4 -0
- package/dist/shared/userDeps/index.js +49 -0
- package/dist/shared/userDeps/shared.d.ts +6 -0
- package/dist/shared/userDeps/shared.js +32 -0
- package/dist/shared/userDeps/userDepsTemplate.d.ts +11 -0
- package/dist/shared/userDeps/userDepsTemplate.js +52 -0
- package/dist/webExport.d.ts +1 -0
- package/dist/webExport.js +37 -0
- package/dist/webServer.d.ts +1 -0
- package/dist/webServer.js +43 -0
- package/dom.d.ts +1 -0
- package/dom.js +2 -0
- package/fixture.d.ts +1 -0
- package/fixture.js +2 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/native.d.ts +1 -0
- package/native.js +2 -0
- package/package.json +42 -0
- package/yarn-error.log +13450 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.webpackExport = webpackExport;
|
|
9
|
+
|
|
10
|
+
var _shared = require("./shared");
|
|
11
|
+
|
|
12
|
+
var _webpackConfig = require("./webpackConfig");
|
|
13
|
+
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
|
|
16
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
17
|
+
|
|
18
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
19
|
+
|
|
20
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
21
|
+
|
|
22
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
23
|
+
|
|
24
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
25
|
+
|
|
26
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
27
|
+
|
|
28
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
|
+
|
|
30
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
31
|
+
|
|
32
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
|
+
|
|
34
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
39
|
+
|
|
40
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
41
|
+
|
|
42
|
+
function webpackExport(_x) {
|
|
43
|
+
return _webpackExport.apply(this, arguments);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _webpackExport() {
|
|
47
|
+
_webpackExport = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
|
|
48
|
+
var cosmosConfig, userWebpack, webpackConfig, webpackError;
|
|
49
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
50
|
+
while (1) {
|
|
51
|
+
switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
cosmosConfig = _ref.cosmosConfig;
|
|
54
|
+
userWebpack = (0, _shared.getWebpack)(cosmosConfig.rootDir);
|
|
55
|
+
|
|
56
|
+
if (userWebpack) {
|
|
57
|
+
_context.next = 4;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return _context.abrupt("return");
|
|
62
|
+
|
|
63
|
+
case 4:
|
|
64
|
+
_context.next = 6;
|
|
65
|
+
return (0, _webpackConfig.getExportWebpackConfig)(cosmosConfig, userWebpack);
|
|
66
|
+
|
|
67
|
+
case 6:
|
|
68
|
+
webpackConfig = _context.sent;
|
|
69
|
+
_context.prev = 7;
|
|
70
|
+
_context.next = 10;
|
|
71
|
+
return runWebpackCompiler(userWebpack, webpackConfig);
|
|
72
|
+
|
|
73
|
+
case 10:
|
|
74
|
+
_context.next = 17;
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case 12:
|
|
78
|
+
_context.prev = 12;
|
|
79
|
+
_context.t0 = _context["catch"](7);
|
|
80
|
+
webpackError = _context.t0;
|
|
81
|
+
|
|
82
|
+
if (webpackError.webpackErrors) {
|
|
83
|
+
webpackError.webpackErrors.forEach(function (error) {
|
|
84
|
+
console.error("".concat(error, "\n"));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
throw webpackError;
|
|
89
|
+
|
|
90
|
+
case 17:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, _callee, null, [[7, 12]]);
|
|
96
|
+
}));
|
|
97
|
+
return _webpackExport.apply(this, arguments);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function runWebpackCompiler(userWebpack, webpackConfig) {
|
|
101
|
+
return new Promise(function (resolve, reject) {
|
|
102
|
+
var compiler = userWebpack(webpackConfig);
|
|
103
|
+
compiler.run(function (err, stats) {
|
|
104
|
+
if (err) {
|
|
105
|
+
reject(err);
|
|
106
|
+
} else if (stats !== null && stats !== void 0 && stats.hasErrors()) {
|
|
107
|
+
var error = new WebpackCompilationError();
|
|
108
|
+
error.webpackErrors = stats.toJson().errors;
|
|
109
|
+
reject(error);
|
|
110
|
+
} else {
|
|
111
|
+
resolve(stats);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var WebpackCompilationError = /*#__PURE__*/function (_Error) {
|
|
118
|
+
_inherits(WebpackCompilationError, _Error);
|
|
119
|
+
|
|
120
|
+
var _super = _createSuper(WebpackCompilationError);
|
|
121
|
+
|
|
122
|
+
function WebpackCompilationError() {
|
|
123
|
+
var _this;
|
|
124
|
+
|
|
125
|
+
_classCallCheck(this, WebpackCompilationError);
|
|
126
|
+
|
|
127
|
+
_this = _super.call(this, 'Webpack errors occurred');
|
|
128
|
+
|
|
129
|
+
_defineProperty(_assertThisInitialized(_this), "webpackErrors", void 0);
|
|
130
|
+
|
|
131
|
+
return _this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return WebpackCompilationError;
|
|
135
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "webpackDevServer", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _devServer.webpackDevServer;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "webpackExport", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _export.webpackExport;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _devServer = require("./devServer");
|
|
20
|
+
|
|
21
|
+
var _export = require("./export");
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getWebpack = getWebpack;
|
|
7
|
+
|
|
8
|
+
var _importFrom = _interopRequireDefault(require("import-from"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function getWebpack(rootDir) {
|
|
13
|
+
var userWebpack = _importFrom.default.silent(rootDir, 'webpack');
|
|
14
|
+
|
|
15
|
+
if (!userWebpack) {
|
|
16
|
+
console.warn('[Cosmos] webpack dependency missing!');
|
|
17
|
+
console.log('Install using "yarn add --dev webpack" or "npm install --save-dev webpack"');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return userWebpack;
|
|
22
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultWebpackConfig = getDefaultWebpackConfig;
|
|
7
|
+
|
|
8
|
+
var _resolveFrom = _interopRequireDefault(require("resolve-from"));
|
|
9
|
+
|
|
10
|
+
var _playgroundHtml = require("../../../shared/playgroundHtml");
|
|
11
|
+
|
|
12
|
+
var _shared = require("./shared");
|
|
13
|
+
|
|
14
|
+
var _htmlPlugin = require("./htmlPlugin");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
// This config doesn't have entry and output set up because it's not meant to
|
|
25
|
+
// work standalone. An entry & output will be added to this base config.
|
|
26
|
+
function getDefaultWebpackConfig(userWebpack, rootDir) {
|
|
27
|
+
// react-cosmos doesn't directly depend on any webpack loader.
|
|
28
|
+
// Instead, it includes the ones already installed by the user.
|
|
29
|
+
var tsLoaderPath = _resolveFrom.default.silent(rootDir, 'ts-loader');
|
|
30
|
+
|
|
31
|
+
var babelLoaderPath = _resolveFrom.default.silent(rootDir, 'next/dist/compiled/babel-loader') || _resolveFrom.default.silent(rootDir, 'babel-loader');
|
|
32
|
+
|
|
33
|
+
var styleLoaderPath = _resolveFrom.default.silent(rootDir, 'style-loader');
|
|
34
|
+
|
|
35
|
+
var cssLoaderPath = _resolveFrom.default.silent(rootDir, 'css-loader');
|
|
36
|
+
|
|
37
|
+
var postcssLoaderPath = _resolveFrom.default.silent(rootDir, 'postcss-loader'); // Note: Since webpack >= v2.0.0, importing of JSON files will work by default
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var jsonLoaderPath = _resolveFrom.default.silent(rootDir, 'json-loader');
|
|
41
|
+
|
|
42
|
+
var rules = [];
|
|
43
|
+
var plugins = []; // Prefer babel-loader over ts-loader if user has both installed. If user
|
|
44
|
+
// has babel-loader installed then most likely they won't want ts-loader
|
|
45
|
+
// to handle module transformation.
|
|
46
|
+
|
|
47
|
+
if (babelLoaderPath) {
|
|
48
|
+
rules.push({
|
|
49
|
+
test: /\.(js|ts)x?$/,
|
|
50
|
+
exclude: /node_modules/,
|
|
51
|
+
use: {
|
|
52
|
+
loader: babelLoaderPath,
|
|
53
|
+
options: {
|
|
54
|
+
root: rootDir
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} else if (tsLoaderPath) {
|
|
59
|
+
rules.push({
|
|
60
|
+
test: /\.tsx?$/,
|
|
61
|
+
loader: tsLoaderPath
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (styleLoaderPath && cssLoaderPath) {
|
|
66
|
+
if (postcssLoaderPath) {
|
|
67
|
+
rules.push({
|
|
68
|
+
test: /\.css$/,
|
|
69
|
+
use: [styleLoaderPath, {
|
|
70
|
+
loader: cssLoaderPath,
|
|
71
|
+
options: {
|
|
72
|
+
importLoaders: 1
|
|
73
|
+
}
|
|
74
|
+
}, postcssLoaderPath],
|
|
75
|
+
exclude: /node_modules/
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
rules.push({
|
|
79
|
+
test: /\.css$/,
|
|
80
|
+
use: [{
|
|
81
|
+
loader: styleLoaderPath
|
|
82
|
+
}, {
|
|
83
|
+
loader: cssLoaderPath
|
|
84
|
+
}],
|
|
85
|
+
exclude: /node_modules/
|
|
86
|
+
});
|
|
87
|
+
} // Preprocess 3rd party .css files located in node_modules
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
rules.push({
|
|
91
|
+
test: /\.css$/,
|
|
92
|
+
use: [{
|
|
93
|
+
loader: styleLoaderPath
|
|
94
|
+
}, {
|
|
95
|
+
loader: cssLoaderPath
|
|
96
|
+
}],
|
|
97
|
+
include: /node_modules/
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (jsonLoaderPath) {
|
|
102
|
+
rules.push({
|
|
103
|
+
test: /\.json$/,
|
|
104
|
+
loader: jsonLoaderPath,
|
|
105
|
+
exclude: /node_modules/
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var htmlWebpackPlugin = (0, _htmlPlugin.getHtmlWebpackPlugin)(rootDir);
|
|
110
|
+
|
|
111
|
+
if (htmlWebpackPlugin) {
|
|
112
|
+
plugins.push(new htmlWebpackPlugin({
|
|
113
|
+
title: 'React Cosmos',
|
|
114
|
+
filename: _playgroundHtml.RENDERER_FILENAME
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
var config = {
|
|
119
|
+
// Besides other advantages, cheap-module-source-map is compatible with
|
|
120
|
+
// React.componentDidCatch https://github.com/facebook/react/issues/10441
|
|
121
|
+
devtool: 'cheap-module-source-map',
|
|
122
|
+
resolve: {
|
|
123
|
+
// Warning: webpack 1.x expects ['', '.js', '.jsx']
|
|
124
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx']
|
|
125
|
+
},
|
|
126
|
+
module: {
|
|
127
|
+
// Note: `module.rules` only works with webpack >=2.x. For 1.x
|
|
128
|
+
// compatibility a custom webpack config (with module.loaders) is required
|
|
129
|
+
rules: rules
|
|
130
|
+
},
|
|
131
|
+
plugins: plugins,
|
|
132
|
+
stats: 'minimal',
|
|
133
|
+
infrastructureLogging: {
|
|
134
|
+
level: 'warn'
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
var webpack4 = userWebpack.version && parseInt(userWebpack.version, 10) >= 4;
|
|
138
|
+
|
|
139
|
+
if (!webpack4) {
|
|
140
|
+
return config;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
144
|
+
mode: (0, _shared.getNodeEnv)(),
|
|
145
|
+
optimization: {
|
|
146
|
+
// Cosmos reads component names at run-time, so it is crucial to not
|
|
147
|
+
// minify even when building with production env (ie. when exporting)
|
|
148
|
+
// https://github.com/react-cosmos/react-cosmos/issues/701
|
|
149
|
+
minimize: false
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDevWebpackConfig = getDevWebpackConfig;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _webpack = require("../cosmosConfig/webpack");
|
|
11
|
+
|
|
12
|
+
var _htmlPlugin = require("./htmlPlugin");
|
|
13
|
+
|
|
14
|
+
var _shared = require("./shared");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
25
|
+
|
|
26
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
27
|
+
|
|
28
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
+
|
|
30
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
31
|
+
|
|
32
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
33
|
+
|
|
34
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
35
|
+
|
|
36
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
37
|
+
|
|
38
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
39
|
+
|
|
40
|
+
function getDevWebpackConfig(_x, _x2) {
|
|
41
|
+
return _getDevWebpackConfig.apply(this, arguments);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _getDevWebpackConfig() {
|
|
45
|
+
_getDevWebpackConfig = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(cosmosConfig, userWebpack) {
|
|
46
|
+
var _webpackConfig$optimi;
|
|
47
|
+
|
|
48
|
+
var baseWebpackConfig, webpackConfig, name;
|
|
49
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
50
|
+
while (1) {
|
|
51
|
+
switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
_context.next = 2;
|
|
54
|
+
return (0, _shared.getUserWebpackConfig)(cosmosConfig, userWebpack);
|
|
55
|
+
|
|
56
|
+
case 2:
|
|
57
|
+
baseWebpackConfig = _context.sent;
|
|
58
|
+
webpackConfig = _objectSpread(_objectSpread({}, baseWebpackConfig), {}, {
|
|
59
|
+
entry: getEntry(cosmosConfig),
|
|
60
|
+
output: getOutput(cosmosConfig),
|
|
61
|
+
module: _objectSpread(_objectSpread({}, baseWebpackConfig.module), {}, {
|
|
62
|
+
rules: getRules(baseWebpackConfig)
|
|
63
|
+
}),
|
|
64
|
+
resolve: (0, _shared.resolveLocalReactDeps)(cosmosConfig, baseWebpackConfig),
|
|
65
|
+
plugins: getPlugins(cosmosConfig, baseWebpackConfig, userWebpack)
|
|
66
|
+
}); // optimization.splitChunks.name = false breaks auto fixture file discovery.
|
|
67
|
+
// When the splitChunks.name is set to false, existing fixtures hot reload
|
|
68
|
+
// fine, but added or removed fixture files don't appear or disappear in the
|
|
69
|
+
// React Cosmos UI automatically — a page refresh is required. The webpack
|
|
70
|
+
// build updates correctly, but module.hot.accept isn't called on the client:
|
|
71
|
+
// https://github.com/react-cosmos/react-cosmos/blob/548e9b7e9ca9fbc66f3915861cf1ae9d60222b28/packages/react-cosmos/src/plugins/webpack/client/index.ts#L24-L29
|
|
72
|
+
// Create React App uses this setting:
|
|
73
|
+
// https://github.com/facebook/create-react-app/blob/37712374bcaa6ccb168eeaf4fe8bd52d120dbc58/packages/react-scripts/config/webpack.config.js#L286
|
|
74
|
+
// Apparently it's a webpack 4 bug:
|
|
75
|
+
// https://twitter.com/wSokra/status/1255925851557974016
|
|
76
|
+
|
|
77
|
+
if ((_webpackConfig$optimi = webpackConfig.optimization) !== null && _webpackConfig$optimi !== void 0 && _webpackConfig$optimi.splitChunks) {
|
|
78
|
+
name = webpackConfig.optimization.splitChunks.name;
|
|
79
|
+
if (name === false) delete webpackConfig.optimization.splitChunks.name;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return _context.abrupt("return", webpackConfig);
|
|
83
|
+
|
|
84
|
+
case 6:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context.stop();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, _callee);
|
|
90
|
+
}));
|
|
91
|
+
return _getDevWebpackConfig.apply(this, arguments);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getEntry(cosmosConfig) {
|
|
95
|
+
var _createWebpackCosmosC = (0, _webpack.createWebpackCosmosConfig)(cosmosConfig),
|
|
96
|
+
hotReload = _createWebpackCosmosC.hotReload; // The React devtools hook needs to be imported before any other module that
|
|
97
|
+
// might import React
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
var devtoolsHook = (0, _shared.resolveClientPath)('reactDevtoolsHook');
|
|
101
|
+
var clientIndex = (0, _shared.resolveClientPath)('index');
|
|
102
|
+
return hotReload ? [devtoolsHook, getHotMiddlewareEntry(), clientIndex] : [devtoolsHook, clientIndex];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getOutput(_ref) {
|
|
106
|
+
var publicUrl = _ref.publicUrl;
|
|
107
|
+
var filename = '[name].js';
|
|
108
|
+
return {
|
|
109
|
+
filename: filename,
|
|
110
|
+
publicPath: publicUrl,
|
|
111
|
+
// Enable click-to-open source in react-error-overlay
|
|
112
|
+
devtoolModuleFilenameTemplate: function devtoolModuleFilenameTemplate(info) {
|
|
113
|
+
return _path.default.resolve(info.absoluteResourcePath).replace(/\\/g, '/');
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getRules(baseWebpackConfig) {
|
|
119
|
+
var existingRules = baseWebpackConfig.module && baseWebpackConfig.module.rules || [];
|
|
120
|
+
return [].concat(_toConsumableArray(existingRules), [(0, _shared.getUserDepsLoaderRule)()]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getPlugins(cosmosConfig, baseWebpackConfig, userWebpack) {
|
|
124
|
+
var existingPlugins = baseWebpackConfig.plugins || [];
|
|
125
|
+
var globalsPlugin = (0, _shared.getGlobalsPlugin)(cosmosConfig, userWebpack, true);
|
|
126
|
+
var noEmitErrorsPlugin = new userWebpack.NoEmitOnErrorsPlugin();
|
|
127
|
+
var plugins = [].concat(_toConsumableArray(existingPlugins), [globalsPlugin, noEmitErrorsPlugin]);
|
|
128
|
+
|
|
129
|
+
var _createWebpackCosmosC2 = (0, _webpack.createWebpackCosmosConfig)(cosmosConfig),
|
|
130
|
+
hotReload = _createWebpackCosmosC2.hotReload;
|
|
131
|
+
|
|
132
|
+
if (hotReload && !(0, _shared.hasPlugin)(plugins, 'HotModuleReplacementPlugin')) {
|
|
133
|
+
var hmrPlugin = new userWebpack.HotModuleReplacementPlugin();
|
|
134
|
+
plugins = [].concat(_toConsumableArray(plugins), [hmrPlugin]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return (0, _htmlPlugin.ensureHtmlWebackPlugin)(cosmosConfig, plugins);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getHotMiddlewareEntry() {
|
|
141
|
+
var clientPath = require.resolve('@skidding/webpack-hot-middleware/client');
|
|
142
|
+
|
|
143
|
+
return "".concat(clientPath, "?reload=true&overlay=false");
|
|
144
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getExportWebpackConfig = getExportWebpackConfig;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _webpack = require("../cosmosConfig/webpack");
|
|
11
|
+
|
|
12
|
+
var _shared = require("../../../shared/shared");
|
|
13
|
+
|
|
14
|
+
var _htmlPlugin = require("./htmlPlugin");
|
|
15
|
+
|
|
16
|
+
var _shared2 = require("./shared");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
27
|
+
|
|
28
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
29
|
+
|
|
30
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
31
|
+
|
|
32
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
33
|
+
|
|
34
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
35
|
+
|
|
36
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
37
|
+
|
|
38
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
39
|
+
|
|
40
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
41
|
+
|
|
42
|
+
function getExportWebpackConfig(_x, _x2) {
|
|
43
|
+
return _getExportWebpackConfig.apply(this, arguments);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _getExportWebpackConfig() {
|
|
47
|
+
_getExportWebpackConfig = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(cosmosConfig, userWebpack) {
|
|
48
|
+
var baseWebpackConfig;
|
|
49
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
50
|
+
while (1) {
|
|
51
|
+
switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
_context.next = 2;
|
|
54
|
+
return (0, _shared2.getUserWebpackConfig)(cosmosConfig, userWebpack);
|
|
55
|
+
|
|
56
|
+
case 2:
|
|
57
|
+
baseWebpackConfig = _context.sent;
|
|
58
|
+
return _context.abrupt("return", _objectSpread(_objectSpread({}, baseWebpackConfig), {}, {
|
|
59
|
+
entry: getEntry(),
|
|
60
|
+
output: getOutput(cosmosConfig),
|
|
61
|
+
module: _objectSpread(_objectSpread({}, baseWebpackConfig.module), {}, {
|
|
62
|
+
rules: getRules(baseWebpackConfig)
|
|
63
|
+
}),
|
|
64
|
+
resolve: (0, _shared2.resolveLocalReactDeps)(cosmosConfig, baseWebpackConfig),
|
|
65
|
+
plugins: getPlugins(cosmosConfig, baseWebpackConfig, userWebpack)
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
case 4:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context.stop();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, _callee);
|
|
74
|
+
}));
|
|
75
|
+
return _getExportWebpackConfig.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getEntry() {
|
|
79
|
+
// The React devtools hook needs to be imported before any other module that
|
|
80
|
+
// might import React
|
|
81
|
+
var devtoolsHook = (0, _shared2.resolveClientPath)('reactDevtoolsHook');
|
|
82
|
+
var clientIndex = (0, _shared2.resolveClientPath)('index');
|
|
83
|
+
return [devtoolsHook, clientIndex];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getOutput(cosmosConfig) {
|
|
87
|
+
var exportPath = cosmosConfig.exportPath,
|
|
88
|
+
publicUrl = cosmosConfig.publicUrl;
|
|
89
|
+
|
|
90
|
+
var _createWebpackCosmosC = (0, _webpack.createWebpackCosmosConfig)(cosmosConfig),
|
|
91
|
+
includeHashInOutputFilename = _createWebpackCosmosC.includeHashInOutputFilename;
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
path: _path.default.resolve(exportPath, (0, _shared.removeLeadingSlash)(publicUrl)),
|
|
95
|
+
filename: includeHashInOutputFilename ? '[name].[contenthash].js' : '[name].js',
|
|
96
|
+
publicPath: publicUrl
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getRules(baseWebpackConfig) {
|
|
101
|
+
var existingRules = baseWebpackConfig.module && baseWebpackConfig.module.rules || [];
|
|
102
|
+
return [].concat(_toConsumableArray(existingRules), [(0, _shared2.getUserDepsLoaderRule)()]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getPlugins(cosmosConfig, baseWebpackConfig, userWebpack) {
|
|
106
|
+
var existingPlugins = baseWebpackConfig.plugins || [];
|
|
107
|
+
var globalsPlugin = (0, _shared2.getGlobalsPlugin)(cosmosConfig, userWebpack, false);
|
|
108
|
+
var noEmitErrorsPlugin = new userWebpack.NoEmitOnErrorsPlugin();
|
|
109
|
+
return (0, _htmlPlugin.ensureHtmlWebackPlugin)(cosmosConfig, [].concat(_toConsumableArray(existingPlugins), [globalsPlugin, noEmitErrorsPlugin]));
|
|
110
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Options as HtmlWebpackPluginOptions } from 'html-webpack-plugin';
|
|
2
|
+
import webpack from 'webpack';
|
|
3
|
+
import { CosmosConfig } from '../../../config';
|
|
4
|
+
export declare type HtmlWebpackPlugin = webpack.WebpackPluginInstance & {
|
|
5
|
+
constructor: HtmlWebpackPluginConstructor;
|
|
6
|
+
} & ({
|
|
7
|
+
options: HtmlWebpackPluginOptions;
|
|
8
|
+
userOptions: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
userOptions: HtmlWebpackPluginOptions;
|
|
11
|
+
options: undefined;
|
|
12
|
+
});
|
|
13
|
+
declare type HtmlWebpackPluginConstructor = new (options?: HtmlWebpackPluginOptions) => HtmlWebpackPlugin;
|
|
14
|
+
export declare function ensureHtmlWebackPlugin({ rootDir }: CosmosConfig, plugins: webpack.WebpackPluginInstance[]): webpack.WebpackPluginInstance[];
|
|
15
|
+
export declare function getHtmlWebpackPlugin(rootDir: string): HtmlWebpackPluginConstructor | null;
|
|
16
|
+
export {};
|