@teambit/webpack 0.0.547 → 0.0.554

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.
@@ -0,0 +1,59 @@
1
+ import webpack, { Configuration } from 'webpack';
2
+ import HtmlWebpackPlugin from 'html-webpack-plugin';
3
+ import { fallbacks } from './webpack-fallbacks';
4
+ import { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';
5
+ import { fallbacksAliases } from './webpack-fallbacks-aliases';
6
+ import { html } from './html';
7
+
8
+ export function previewConfigFactory(entries: string[], rootPath: string): Configuration {
9
+ return {
10
+ mode: 'production',
11
+ // Stop compilation early in production
12
+ bail: true,
13
+ // These are the "entry points" to our application.
14
+ // This means they will be the "root" imports that are included in JS bundle.
15
+ entry: entries.filter(Boolean),
16
+
17
+ output: {
18
+ // The build folder.
19
+ path: `${rootPath}/public`,
20
+
21
+ filename: 'static/js/[name].[contenthash:8].js',
22
+ // There are also additional JS chunk files if you use code splitting.
23
+ chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
24
+ },
25
+
26
+ resolve: {
27
+ alias: fallbacksAliases,
28
+
29
+ fallback: fallbacks,
30
+ },
31
+
32
+ plugins: [
33
+ new HtmlWebpackPlugin(
34
+ Object.assign(
35
+ {},
36
+ {
37
+ inject: true,
38
+ templateContent: html('Preview'),
39
+ },
40
+ {
41
+ minify: {
42
+ removeComments: true,
43
+ collapseWhitespace: true,
44
+ removeRedundantAttributes: true,
45
+ useShortDoctype: true,
46
+ removeEmptyAttributes: true,
47
+ removeStyleLinkTypeAttributes: true,
48
+ keepClosingSlash: true,
49
+ minifyJS: true,
50
+ minifyCSS: true,
51
+ minifyURLs: true,
52
+ },
53
+ }
54
+ )
55
+ ),
56
+ new webpack.ProvidePlugin(fallbacksProvidePluginConfig),
57
+ ],
58
+ };
59
+ }
@@ -1,9 +1,7 @@
1
1
  import webpack, { Configuration } from 'webpack';
2
- import HtmlWebpackPlugin from 'html-webpack-plugin';
3
2
  import { fallbacks } from './webpack-fallbacks';
4
3
  import { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';
5
4
  import { fallbacksAliases } from './webpack-fallbacks-aliases';
6
- import { html } from './html';
7
5
 
8
6
  export function configFactory(entries: string[], rootPath: string): Configuration {
9
7
  return {
@@ -29,31 +27,6 @@ export function configFactory(entries: string[], rootPath: string): Configuratio
29
27
  fallback: fallbacks,
30
28
  },
31
29
 
32
- plugins: [
33
- new HtmlWebpackPlugin(
34
- Object.assign(
35
- {},
36
- {
37
- inject: true,
38
- templateContent: html('Preview'),
39
- },
40
- {
41
- minify: {
42
- removeComments: true,
43
- collapseWhitespace: true,
44
- removeRedundantAttributes: true,
45
- useShortDoctype: true,
46
- removeEmptyAttributes: true,
47
- removeStyleLinkTypeAttributes: true,
48
- keepClosingSlash: true,
49
- minifyJS: true,
50
- minifyCSS: true,
51
- minifyURLs: true,
52
- },
53
- }
54
- )
55
- ),
56
- new webpack.ProvidePlugin(fallbacksProvidePluginConfig),
57
- ],
30
+ plugins: [new webpack.ProvidePlugin(fallbacksProvidePluginConfig)],
58
31
  };
59
32
  }
@@ -0,0 +1,2 @@
1
+ import { Configuration } from 'webpack';
2
+ export declare function previewConfigFactory(entries: string[], rootPath: string): Configuration;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.previewConfigFactory = previewConfigFactory;
9
+
10
+ function _webpack() {
11
+ const data = _interopRequireDefault(require("webpack"));
12
+
13
+ _webpack = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ function _htmlWebpackPlugin() {
21
+ const data = _interopRequireDefault(require("html-webpack-plugin"));
22
+
23
+ _htmlWebpackPlugin = function () {
24
+ return data;
25
+ };
26
+
27
+ return data;
28
+ }
29
+
30
+ function _webpackFallbacks() {
31
+ const data = require("./webpack-fallbacks");
32
+
33
+ _webpackFallbacks = function () {
34
+ return data;
35
+ };
36
+
37
+ return data;
38
+ }
39
+
40
+ function _webpackFallbacksProvidePluginConfig() {
41
+ const data = require("./webpack-fallbacks-provide-plugin-config");
42
+
43
+ _webpackFallbacksProvidePluginConfig = function () {
44
+ return data;
45
+ };
46
+
47
+ return data;
48
+ }
49
+
50
+ function _webpackFallbacksAliases() {
51
+ const data = require("./webpack-fallbacks-aliases");
52
+
53
+ _webpackFallbacksAliases = function () {
54
+ return data;
55
+ };
56
+
57
+ return data;
58
+ }
59
+
60
+ function _html() {
61
+ const data = require("./html");
62
+
63
+ _html = function () {
64
+ return data;
65
+ };
66
+
67
+ return data;
68
+ }
69
+
70
+ function previewConfigFactory(entries, rootPath) {
71
+ return {
72
+ mode: 'production',
73
+ // Stop compilation early in production
74
+ bail: true,
75
+ // These are the "entry points" to our application.
76
+ // This means they will be the "root" imports that are included in JS bundle.
77
+ entry: entries.filter(Boolean),
78
+ output: {
79
+ // The build folder.
80
+ path: `${rootPath}/public`,
81
+ filename: 'static/js/[name].[contenthash:8].js',
82
+ // There are also additional JS chunk files if you use code splitting.
83
+ chunkFilename: 'static/js/[name].[contenthash:8].chunk.js'
84
+ },
85
+ resolve: {
86
+ alias: _webpackFallbacksAliases().fallbacksAliases,
87
+ fallback: _webpackFallbacks().fallbacks
88
+ },
89
+ plugins: [new (_htmlWebpackPlugin().default)(Object.assign({}, {
90
+ inject: true,
91
+ templateContent: (0, _html().html)('Preview')
92
+ }, {
93
+ minify: {
94
+ removeComments: true,
95
+ collapseWhitespace: true,
96
+ removeRedundantAttributes: true,
97
+ useShortDoctype: true,
98
+ removeEmptyAttributes: true,
99
+ removeStyleLinkTypeAttributes: true,
100
+ keepClosingSlash: true,
101
+ minifyJS: true,
102
+ minifyCSS: true,
103
+ minifyURLs: true
104
+ }
105
+ })), new (_webpack().default.ProvidePlugin)(_webpackFallbacksProvidePluginConfig().fallbacksProvidePluginConfig)]
106
+ };
107
+ }
108
+
109
+ //# sourceMappingURL=webpack-preview.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["webpack-preview.config.ts"],"names":["previewConfigFactory","entries","rootPath","mode","bail","entry","filter","Boolean","output","path","filename","chunkFilename","resolve","alias","fallbacksAliases","fallback","fallbacks","plugins","HtmlWebpackPlugin","Object","assign","inject","templateContent","minify","removeComments","collapseWhitespace","removeRedundantAttributes","useShortDoctype","removeEmptyAttributes","removeStyleLinkTypeAttributes","keepClosingSlash","minifyJS","minifyCSS","minifyURLs","webpack","ProvidePlugin","fallbacksProvidePluginConfig"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,SAASA,oBAAT,CAA8BC,OAA9B,EAAiDC,QAAjD,EAAkF;AACvF,SAAO;AACLC,IAAAA,IAAI,EAAE,YADD;AAEL;AACAC,IAAAA,IAAI,EAAE,IAHD;AAIL;AACA;AACAC,IAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,CAAeC,OAAf,CANF;AAQLC,IAAAA,MAAM,EAAE;AACN;AACAC,MAAAA,IAAI,EAAG,GAAEP,QAAS,SAFZ;AAINQ,MAAAA,QAAQ,EAAE,qCAJJ;AAKN;AACAC,MAAAA,aAAa,EAAE;AANT,KARH;AAiBLC,IAAAA,OAAO,EAAE;AACPC,MAAAA,KAAK,EAAEC,2CADA;AAGPC,MAAAA,QAAQ,EAAEC;AAHH,KAjBJ;AAuBLC,IAAAA,OAAO,EAAE,CACP,KAAIC,4BAAJ,EACEC,MAAM,CAACC,MAAP,CACE,EADF,EAEE;AACEC,MAAAA,MAAM,EAAE,IADV;AAEEC,MAAAA,eAAe,EAAE,kBAAK,SAAL;AAFnB,KAFF,EAME;AACEC,MAAAA,MAAM,EAAE;AACNC,QAAAA,cAAc,EAAE,IADV;AAENC,QAAAA,kBAAkB,EAAE,IAFd;AAGNC,QAAAA,yBAAyB,EAAE,IAHrB;AAINC,QAAAA,eAAe,EAAE,IAJX;AAKNC,QAAAA,qBAAqB,EAAE,IALjB;AAMNC,QAAAA,6BAA6B,EAAE,IANzB;AAONC,QAAAA,gBAAgB,EAAE,IAPZ;AAQNC,QAAAA,QAAQ,EAAE,IARJ;AASNC,QAAAA,SAAS,EAAE,IATL;AAUNC,QAAAA,UAAU,EAAE;AAVN;AADV,KANF,CADF,CADO,EAwBP,KAAIC,mBAAQC,aAAZ,EAA0BC,mEAA1B,CAxBO;AAvBJ,GAAP;AAkDD","sourcesContent":["import webpack, { Configuration } from 'webpack';\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport { fallbacks } from './webpack-fallbacks';\nimport { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';\nimport { fallbacksAliases } from './webpack-fallbacks-aliases';\nimport { html } from './html';\n\nexport function previewConfigFactory(entries: string[], rootPath: string): Configuration {\n return {\n mode: 'production',\n // Stop compilation early in production\n bail: true,\n // These are the \"entry points\" to our application.\n // This means they will be the \"root\" imports that are included in JS bundle.\n entry: entries.filter(Boolean),\n\n output: {\n // The build folder.\n path: `${rootPath}/public`,\n\n filename: 'static/js/[name].[contenthash:8].js',\n // There are also additional JS chunk files if you use code splitting.\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',\n },\n\n resolve: {\n alias: fallbacksAliases,\n\n fallback: fallbacks,\n },\n\n plugins: [\n new HtmlWebpackPlugin(\n Object.assign(\n {},\n {\n inject: true,\n templateContent: html('Preview'),\n },\n {\n minify: {\n removeComments: true,\n collapseWhitespace: true,\n removeRedundantAttributes: true,\n useShortDoctype: true,\n removeEmptyAttributes: true,\n removeStyleLinkTypeAttributes: true,\n keepClosingSlash: true,\n minifyJS: true,\n minifyCSS: true,\n minifyURLs: true,\n },\n }\n )\n ),\n new webpack.ProvidePlugin(fallbacksProvidePluginConfig),\n ],\n };\n}\n"]}
@@ -17,16 +17,6 @@ function _webpack() {
17
17
  return data;
18
18
  }
19
19
 
20
- function _htmlWebpackPlugin() {
21
- const data = _interopRequireDefault(require("html-webpack-plugin"));
22
-
23
- _htmlWebpackPlugin = function () {
24
- return data;
25
- };
26
-
27
- return data;
28
- }
29
-
30
20
  function _webpackFallbacks() {
31
21
  const data = require("./webpack-fallbacks");
32
22
 
@@ -57,16 +47,6 @@ function _webpackFallbacksAliases() {
57
47
  return data;
58
48
  }
59
49
 
60
- function _html() {
61
- const data = require("./html");
62
-
63
- _html = function () {
64
- return data;
65
- };
66
-
67
- return data;
68
- }
69
-
70
50
  function configFactory(entries, rootPath) {
71
51
  return {
72
52
  mode: 'production',
@@ -86,23 +66,7 @@ function configFactory(entries, rootPath) {
86
66
  alias: _webpackFallbacksAliases().fallbacksAliases,
87
67
  fallback: _webpackFallbacks().fallbacks
88
68
  },
89
- plugins: [new (_htmlWebpackPlugin().default)(Object.assign({}, {
90
- inject: true,
91
- templateContent: (0, _html().html)('Preview')
92
- }, {
93
- minify: {
94
- removeComments: true,
95
- collapseWhitespace: true,
96
- removeRedundantAttributes: true,
97
- useShortDoctype: true,
98
- removeEmptyAttributes: true,
99
- removeStyleLinkTypeAttributes: true,
100
- keepClosingSlash: true,
101
- minifyJS: true,
102
- minifyCSS: true,
103
- minifyURLs: true
104
- }
105
- })), new (_webpack().default.ProvidePlugin)(_webpackFallbacksProvidePluginConfig().fallbacksProvidePluginConfig)]
69
+ plugins: [new (_webpack().default.ProvidePlugin)(_webpackFallbacksProvidePluginConfig().fallbacksProvidePluginConfig)]
106
70
  };
107
71
  }
108
72
 
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack.config.ts"],"names":["configFactory","entries","rootPath","mode","bail","entry","filter","Boolean","output","path","filename","chunkFilename","resolve","alias","fallbacksAliases","fallback","fallbacks","plugins","HtmlWebpackPlugin","Object","assign","inject","templateContent","minify","removeComments","collapseWhitespace","removeRedundantAttributes","useShortDoctype","removeEmptyAttributes","removeStyleLinkTypeAttributes","keepClosingSlash","minifyJS","minifyCSS","minifyURLs","webpack","ProvidePlugin","fallbacksProvidePluginConfig"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,SAASA,aAAT,CAAuBC,OAAvB,EAA0CC,QAA1C,EAA2E;AAChF,SAAO;AACLC,IAAAA,IAAI,EAAE,YADD;AAEL;AACAC,IAAAA,IAAI,EAAE,IAHD;AAIL;AACA;AACAC,IAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,CAAeC,OAAf,CANF;AAQLC,IAAAA,MAAM,EAAE;AACN;AACAC,MAAAA,IAAI,EAAG,GAAEP,QAAS,SAFZ;AAINQ,MAAAA,QAAQ,EAAE,qCAJJ;AAKN;AACAC,MAAAA,aAAa,EAAE;AANT,KARH;AAiBLC,IAAAA,OAAO,EAAE;AACPC,MAAAA,KAAK,EAAEC,2CADA;AAGPC,MAAAA,QAAQ,EAAEC;AAHH,KAjBJ;AAuBLC,IAAAA,OAAO,EAAE,CACP,KAAIC,4BAAJ,EACEC,MAAM,CAACC,MAAP,CACE,EADF,EAEE;AACEC,MAAAA,MAAM,EAAE,IADV;AAEEC,MAAAA,eAAe,EAAE,kBAAK,SAAL;AAFnB,KAFF,EAME;AACEC,MAAAA,MAAM,EAAE;AACNC,QAAAA,cAAc,EAAE,IADV;AAENC,QAAAA,kBAAkB,EAAE,IAFd;AAGNC,QAAAA,yBAAyB,EAAE,IAHrB;AAINC,QAAAA,eAAe,EAAE,IAJX;AAKNC,QAAAA,qBAAqB,EAAE,IALjB;AAMNC,QAAAA,6BAA6B,EAAE,IANzB;AAONC,QAAAA,gBAAgB,EAAE,IAPZ;AAQNC,QAAAA,QAAQ,EAAE,IARJ;AASNC,QAAAA,SAAS,EAAE,IATL;AAUNC,QAAAA,UAAU,EAAE;AAVN;AADV,KANF,CADF,CADO,EAwBP,KAAIC,mBAAQC,aAAZ,EAA0BC,mEAA1B,CAxBO;AAvBJ,GAAP;AAkDD","sourcesContent":["import webpack, { Configuration } from 'webpack';\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport { fallbacks } from './webpack-fallbacks';\nimport { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';\nimport { fallbacksAliases } from './webpack-fallbacks-aliases';\nimport { html } from './html';\n\nexport function configFactory(entries: string[], rootPath: string): Configuration {\n return {\n mode: 'production',\n // Stop compilation early in production\n bail: true,\n // These are the \"entry points\" to our application.\n // This means they will be the \"root\" imports that are included in JS bundle.\n entry: entries.filter(Boolean),\n\n output: {\n // The build folder.\n path: `${rootPath}/public`,\n\n filename: 'static/js/[name].[contenthash:8].js',\n // There are also additional JS chunk files if you use code splitting.\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',\n },\n\n resolve: {\n alias: fallbacksAliases,\n\n fallback: fallbacks,\n },\n\n plugins: [\n new HtmlWebpackPlugin(\n Object.assign(\n {},\n {\n inject: true,\n templateContent: html('Preview'),\n },\n {\n minify: {\n removeComments: true,\n collapseWhitespace: true,\n removeRedundantAttributes: true,\n useShortDoctype: true,\n removeEmptyAttributes: true,\n removeStyleLinkTypeAttributes: true,\n keepClosingSlash: true,\n minifyJS: true,\n minifyCSS: true,\n minifyURLs: true,\n },\n }\n )\n ),\n new webpack.ProvidePlugin(fallbacksProvidePluginConfig),\n ],\n };\n}\n"]}
1
+ {"version":3,"sources":["webpack.config.ts"],"names":["configFactory","entries","rootPath","mode","bail","entry","filter","Boolean","output","path","filename","chunkFilename","resolve","alias","fallbacksAliases","fallback","fallbacks","plugins","webpack","ProvidePlugin","fallbacksProvidePluginConfig"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,SAASA,aAAT,CAAuBC,OAAvB,EAA0CC,QAA1C,EAA2E;AAChF,SAAO;AACLC,IAAAA,IAAI,EAAE,YADD;AAEL;AACAC,IAAAA,IAAI,EAAE,IAHD;AAIL;AACA;AACAC,IAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,CAAeC,OAAf,CANF;AAQLC,IAAAA,MAAM,EAAE;AACN;AACAC,MAAAA,IAAI,EAAG,GAAEP,QAAS,SAFZ;AAINQ,MAAAA,QAAQ,EAAE,qCAJJ;AAKN;AACAC,MAAAA,aAAa,EAAE;AANT,KARH;AAiBLC,IAAAA,OAAO,EAAE;AACPC,MAAAA,KAAK,EAAEC,2CADA;AAGPC,MAAAA,QAAQ,EAAEC;AAHH,KAjBJ;AAuBLC,IAAAA,OAAO,EAAE,CAAC,KAAIC,mBAAQC,aAAZ,EAA0BC,mEAA1B,CAAD;AAvBJ,GAAP;AAyBD","sourcesContent":["import webpack, { Configuration } from 'webpack';\nimport { fallbacks } from './webpack-fallbacks';\nimport { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';\nimport { fallbacksAliases } from './webpack-fallbacks-aliases';\n\nexport function configFactory(entries: string[], rootPath: string): Configuration {\n return {\n mode: 'production',\n // Stop compilation early in production\n bail: true,\n // These are the \"entry points\" to our application.\n // This means they will be the \"root\" imports that are included in JS bundle.\n entry: entries.filter(Boolean),\n\n output: {\n // The build folder.\n path: `${rootPath}/public`,\n\n filename: 'static/js/[name].[contenthash:8].js',\n // There are also additional JS chunk files if you use code splitting.\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',\n },\n\n resolve: {\n alias: fallbacksAliases,\n\n fallback: fallbacks,\n },\n\n plugins: [new webpack.ProvidePlugin(fallbacksProvidePluginConfig)],\n };\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { WebpackMain, WebpackConfigTransformer, WebpackConfigTransformContext } from './webpack.main.runtime';
1
+ export type { WebpackMain, WebpackConfigTransformer, WebpackConfigTransformContext, WebpackConfigDevServerTransformContext, GlobalWebpackConfigTransformContext, WebpackConfigDevServerTransformer, } from './webpack.main.runtime';
2
2
  export { runTransformersWithContext } from './webpack.main.runtime';
3
3
  export { WebpackAspect } from './webpack.aspect';
4
4
  export { WebpackDevServer } from './webpack.dev-server';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export type { WebpackMain, WebpackConfigTransformer, WebpackConfigTransformContext } from './webpack.main.runtime';\nexport { runTransformersWithContext } from './webpack.main.runtime';\nexport { WebpackAspect } from './webpack.aspect';\nexport { WebpackDevServer } from './webpack.dev-server';\nexport { WebpackBundler } from './webpack.bundler';\nexport type { WebpackConfigWithDevServer } from './webpack.dev-server';\nexport * from './events';\nexport { Configuration } from 'webpack';\nexport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\nexport { WebpackBitReporterPlugin } from './plugins/webpack-bit-reporter-plugin';\nexport { fallbacks } from './config/webpack-fallbacks';\nexport { fallbacksAliases } from './config/webpack-fallbacks-aliases';\nexport { fallbacksProvidePluginConfig } from './config/webpack-fallbacks-provide-plugin-config';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export type {\n WebpackMain,\n WebpackConfigTransformer,\n WebpackConfigTransformContext,\n WebpackConfigDevServerTransformContext,\n GlobalWebpackConfigTransformContext,\n WebpackConfigDevServerTransformer,\n} from './webpack.main.runtime';\nexport { runTransformersWithContext } from './webpack.main.runtime';\nexport { WebpackAspect } from './webpack.aspect';\nexport { WebpackDevServer } from './webpack.dev-server';\nexport { WebpackBundler } from './webpack.bundler';\nexport type { WebpackConfigWithDevServer } from './webpack.dev-server';\nexport * from './events';\nexport { Configuration } from 'webpack';\nexport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\nexport { WebpackBitReporterPlugin } from './plugins/webpack-bit-reporter-plugin';\nexport { fallbacks } from './config/webpack-fallbacks';\nexport { fallbacksAliases } from './config/webpack-fallbacks-aliases';\nexport { fallbacksProvidePluginConfig } from './config/webpack-fallbacks-provide-plugin-config';\n"]}
@@ -48,6 +48,7 @@ class WebpackBundler {
48
48
  }
49
49
 
50
50
  async run() {
51
+ const startTime = Date.now();
51
52
  const compilers = this.configs.map(config => this.webpack(config));
52
53
  const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);
53
54
  const componentOutput = await (0, _pMapSeries().default)(compilers, compiler => {
@@ -70,7 +71,9 @@ class WebpackBundler {
70
71
  errors: info.errors,
71
72
  outputPath: stats.compilation.outputOptions.path,
72
73
  components,
73
- warnings: info.warnings
74
+ warnings: info.warnings,
75
+ startTime,
76
+ endTime: Date.now()
74
77
  });
75
78
  });
76
79
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack.bundler.ts"],"names":["WebpackBundler","constructor","targets","configs","logger","webpack","run","compilers","map","config","longProcessLogger","createLongProcessLogger","length","componentOutput","compiler","components","getComponents","outputPath","logProgress","component","id","toString","join","Promise","resolve","err","stats","errors","stack","BitError","info","toJson","compilation","outputOptions","path","warnings","end","splitPath","split","pop","target","find","targetCandidate","Error"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;AAC7CC,EAAAA,WAAW;AACT;AACJ;AACA;A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ACbG,YAAAA,MAAM,EAAEG,IAAI,CAACH,MADA;AAEbV,YAAAA,UAAU,EAAES,KAAK,CAACM,WAAN,CAAkBC,aAAlB,CAAgCC,IAF/B;AAGbnB,YAAAA,UAHa;AAIboB,YAAAA,QAAQ,EAAEL,IAAI,CAACK;AAJF,WAAD,CAAd;AAMD,SAfM,CAAP;AAgBD,OAnBM,CAAP;AAoBD,KAvB6B,CAA9B;AAwBAzB,IAAAA,iBAAiB,CAAC0B,GAAlB;AACA,WAAOvB,eAAP;AACD;;AAEOG,EAAAA,aAAa,CAACC,UAAD,EAAqB;AACxC,UAAMoB,SAAS,GAAGpB,UAAU,CAACqB,KAAX,CAAiB,GAAjB,CAAlB;AACAD,IAAAA,SAAS,CAACE,GAAV;AACA,UAAML,IAAI,GAAGG,SAAS,CAACf,IAAV,CAAe,GAAf,CAAb;AACA,UAAMkB,MAAM,GAAG,KAAKtC,OAAL,CAAauC,IAAb,CAAmBC,eAAD,IAAqB;AACpD,aAAOR,IAAI,KAAKQ,eAAe,CAACzB,UAAhC;AACD,KAFc,CAAf;;AAIA,QAAI,CAACuB,MAAL,EAAa;AACX,YAAM,IAAIG,KAAJ,CAAW,yCAAwCT,IAAK,GAAxD,CAAN;AACD;;AAED,WAAOM,MAAM,CAACzB,UAAd;AACD;;AA7D4C","sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport { Bundler, BundlerResult, Target } from '@teambit/bundler';\nimport { Logger } from '@teambit/logger';\nimport mapSeries from 'p-map-series';\nimport { Compiler, Configuration } from 'webpack';\n\nexport class WebpackBundler implements Bundler {\n constructor(\n /**\n * targets to bundle.\n */\n private targets: Target[],\n\n /**\n * webpack configuration.\n */\n private configs: Configuration[],\n\n private logger: Logger,\n\n private webpack\n ) {}\n\n async run(): Promise<BundlerResult[]> {\n const compilers = this.configs.map((config: any) => this.webpack(config));\n const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);\n const componentOutput = await mapSeries(compilers, (compiler: Compiler) => {\n const components = this.getComponents(compiler.outputPath);\n longProcessLogger.logProgress(components.map((component) => component.id.toString()).join(', '));\n return new Promise((resolve) => {\n // TODO: split to multiple processes to reduce time and configure concurrent builds.\n // @see https://github.com/trivago/parallel-webpack\n return compiler.run((err, stats) => {\n if (err) {\n return resolve({\n errors: [`${err.toString()}\\n${err.stack}`],\n components,\n });\n }\n if (!stats) throw new BitError('unknown build error');\n const info = stats.toJson();\n return resolve({\n errors: info.errors,\n outputPath: stats.compilation.outputOptions.path,\n components,\n warnings: info.warnings,\n });\n });\n });\n });\n longProcessLogger.end();\n return componentOutput as BundlerResult[];\n }\n\n private getComponents(outputPath: string) {\n const splitPath = outputPath.split('/');\n splitPath.pop();\n const path = splitPath.join('/');\n const target = this.targets.find((targetCandidate) => {\n return path === targetCandidate.outputPath;\n });\n\n if (!target) {\n throw new Error(`Could not find component id for path \"${path}\"`);\n }\n\n return target.components;\n }\n}\n"]}
1
+ {"version":3,"sources":["webpack.bundler.ts"],"names":["WebpackBundler","constructor","targets","configs","logger","webpack","run","startTime","Date","now","compilers","map","config","longProcessLogger","createLongProcessLogger","length","componentOutput","compiler","components","getComponents","outputPath","logProgress","component","id","toString","join","Promise","resolve","err","stats","errors","stack","BitError","info","toJson","compilation","outputOptions","path","warnings","endTime","end","splitPath","split","pop","target","find","targetCandidate","Error"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;AAC7CC,EAAAA,WAAW;AACT;AACJ;AACA;AACYC,EAAAA,OAJC;AAMT;AACJ;AACA;AACYC,EAAAA,OATC,EAWDC,MAXC,EAaDC,OAbC,EAcT;AAAA,SAVQH,OAUR,GAVQA,OAUR;AAAA,SALQC,OAKR,GALQA,OAKR;AAAA,SAHQC,MAGR,GAHQA,MAGR;AAAA,SADQC,OACR,GADQA,OACR;AAAE;;AAEK,QAAHC,GA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AJF;AAKb/B,YAAAA,SALa;AAMbgC,YAAAA,OAAO,EAAE/B,IAAI,CAACC,GAAL;AANI,WAAD,CAAd;AAQD,SAjBM,CAAP;AAkBD,OArBM,CAAP;AAsBD,KAzB6B,CAA9B;AA0BAI,IAAAA,iBAAiB,CAAC2B,GAAlB;AACA,WAAOxB,eAAP;AACD;;AAEOG,EAAAA,aAAa,CAACC,UAAD,EAAqB;AACxC,UAAMqB,SAAS,GAAGrB,UAAU,CAACsB,KAAX,CAAiB,GAAjB,CAAlB;AACAD,IAAAA,SAAS,CAACE,GAAV;AACA,UAAMN,IAAI,GAAGI,SAAS,CAAChB,IAAV,CAAe,GAAf,CAAb;AACA,UAAMmB,MAAM,GAAG,KAAK1C,OAAL,CAAa2C,IAAb,CAAmBC,eAAD,IAAqB;AACpD,aAAOT,IAAI,KAAKS,eAAe,CAAC1B,UAAhC;AACD,KAFc,CAAf;;AAIA,QAAI,CAACwB,MAAL,EAAa;AACX,YAAM,IAAIG,KAAJ,CAAW,yCAAwCV,IAAK,GAAxD,CAAN;AACD;;AAED,WAAOO,MAAM,CAAC1B,UAAd;AACD;;AAhE4C","sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport { Bundler, BundlerResult, Target } from '@teambit/bundler';\nimport { Logger } from '@teambit/logger';\nimport mapSeries from 'p-map-series';\nimport { Compiler, Configuration } from 'webpack';\n\nexport class WebpackBundler implements Bundler {\n constructor(\n /**\n * targets to bundle.\n */\n private targets: Target[],\n\n /**\n * webpack configuration.\n */\n private configs: Configuration[],\n\n private logger: Logger,\n\n private webpack\n ) {}\n\n async run(): Promise<BundlerResult[]> {\n const startTime = Date.now();\n const compilers = this.configs.map((config: any) => this.webpack(config));\n const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);\n const componentOutput = await mapSeries(compilers, (compiler: Compiler) => {\n const components = this.getComponents(compiler.outputPath);\n longProcessLogger.logProgress(components.map((component) => component.id.toString()).join(', '));\n return new Promise((resolve) => {\n // TODO: split to multiple processes to reduce time and configure concurrent builds.\n // @see https://github.com/trivago/parallel-webpack\n return compiler.run((err, stats) => {\n if (err) {\n return resolve({\n errors: [`${err.toString()}\\n${err.stack}`],\n components,\n });\n }\n if (!stats) throw new BitError('unknown build error');\n const info = stats.toJson();\n return resolve({\n errors: info.errors,\n outputPath: stats.compilation.outputOptions.path,\n components,\n warnings: info.warnings,\n startTime,\n endTime: Date.now(),\n });\n });\n });\n });\n longProcessLogger.end();\n return componentOutput as BundlerResult[];\n }\n\n private getComponents(outputPath: string) {\n const splitPath = outputPath.split('/');\n splitPath.pop();\n const path = splitPath.join('/');\n const target = this.targets.find((targetCandidate) => {\n return path === targetCandidate.outputPath;\n });\n\n if (!target) {\n throw new Error(`Could not find component id for path \"${path}\"`);\n }\n\n return target.components;\n }\n}\n"]}
@@ -1,13 +1,19 @@
1
+ import webpack from 'webpack';
1
2
  import { PubsubMain } from '@teambit/pubsub';
2
- import { BundlerContext, BundlerMain, DevServer, DevServerContext, BundlerMode } from '@teambit/bundler';
3
+ import { BundlerContext, BundlerMain, DevServer, DevServerContext, BundlerMode, Target } from '@teambit/bundler';
3
4
  import { Logger, LoggerMain } from '@teambit/logger';
4
5
  import { Workspace } from '@teambit/workspace';
5
6
  import { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
6
7
  import { WebpackBundler } from './webpack.bundler';
7
- export declare type WebpackConfigTransformContext = {
8
+ export declare type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {
9
+ target: Target;
10
+ };
11
+ export declare type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext;
12
+ export declare type GlobalWebpackConfigTransformContext = {
8
13
  mode: BundlerMode;
9
14
  };
10
15
  export declare type WebpackConfigTransformer = (config: WebpackConfigMutator, context: WebpackConfigTransformContext) => WebpackConfigMutator;
16
+ export declare type WebpackConfigDevServerTransformer = (config: WebpackConfigMutator, context: WebpackConfigDevServerTransformContext) => WebpackConfigMutator;
11
17
  export declare class WebpackMain {
12
18
  pubsub: PubsubMain;
13
19
  private workspace;
@@ -16,7 +22,10 @@ export declare class WebpackMain {
16
22
  constructor(pubsub: PubsubMain, workspace: Workspace, bundler: BundlerMain, logger: Logger);
17
23
  createDevServer(context: DevServerContext, transformers?: WebpackConfigTransformer[]): DevServer;
18
24
  mergeConfig(target: any, source: any): any;
19
- createBundler(context: BundlerContext, transformers?: WebpackConfigTransformer[]): WebpackBundler;
25
+ createBundler(context: BundlerContext, transformers?: WebpackConfigTransformer[], initialConfigs?: webpack.Configuration[]): WebpackBundler;
26
+ createPreviewBundler(context: BundlerContext, transformers?: WebpackConfigTransformer[]): WebpackBundler;
27
+ private createConfigs;
28
+ private createEmptyConfigs;
20
29
  private createPreviewConfig;
21
30
  private createDevServerConfig;
22
31
  static slots: never[];
@@ -24,4 +33,4 @@ export declare class WebpackMain {
24
33
  static dependencies: import("@teambit/harmony").Aspect[];
25
34
  static provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]): Promise<WebpackMain>;
26
35
  }
27
- export declare function runTransformersWithContext(config: WebpackConfigMutator, transformers: WebpackConfigTransformer[] | undefined, context: WebpackConfigTransformContext): WebpackConfigMutator;
36
+ export declare function runTransformersWithContext(config: WebpackConfigMutator, transformers: (WebpackConfigTransformer | WebpackConfigDevServerTransformer)[] | undefined, context: WebpackConfigTransformContext | WebpackConfigDevServerTransformContext): WebpackConfigMutator;
@@ -22,6 +22,16 @@ function _defineProperty2() {
22
22
  return data;
23
23
  }
24
24
 
25
+ function _webpack() {
26
+ const data = _interopRequireDefault(require("webpack"));
27
+
28
+ _webpack = function () {
29
+ return data;
30
+ };
31
+
32
+ return data;
33
+ }
34
+
25
35
  function _pubsub() {
26
36
  const data = _interopRequireDefault(require("@teambit/pubsub"));
27
37
 
@@ -82,16 +92,6 @@ function _webpackMerge() {
82
92
  return data;
83
93
  }
84
94
 
85
- function _webpack() {
86
- const data = _interopRequireDefault(require("webpack"));
87
-
88
- _webpack = function () {
89
- return data;
90
- };
91
-
92
- return data;
93
- }
94
-
95
95
  function _webpackDevServer() {
96
96
  const data = _interopRequireDefault(require("webpack-dev-server"));
97
97
 
@@ -122,6 +122,16 @@ function _webpackDev() {
122
122
  return data;
123
123
  }
124
124
 
125
+ function _webpackPreview() {
126
+ const data = require("./config/webpack-preview.config");
127
+
128
+ _webpackPreview = function () {
129
+ return data;
130
+ };
131
+
132
+ return data;
133
+ }
134
+
125
135
  function _webpack2() {
126
136
  const data = require("./config/webpack.config");
127
137
 
@@ -205,25 +215,42 @@ class WebpackMain {
205
215
  return (0, _webpackMerge().merge)(target, source);
206
216
  }
207
217
 
208
- createBundler(context, transformers = []) {
209
- const configs = this.createPreviewConfig(context.targets);
218
+ createBundler(context, transformers = [], initialConfigs) {
210
219
  const transformerContext = {
211
220
  mode: 'prod'
212
221
  };
213
- const mutatedConfigs = configs.map(config => {
214
- const configMutator = new (_webpackModules().WebpackConfigMutator)(config);
215
- const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
216
- return afterMutation.raw;
217
- });
218
- return new (_webpack4().WebpackBundler)(context.targets, mutatedConfigs, this.logger, _webpack().default);
222
+ const configs = initialConfigs || this.createEmptyConfigs(context.targets, transformers, transformerContext);
223
+ return new (_webpack4().WebpackBundler)(context.targets, configs, this.logger, _webpack().default);
219
224
  }
220
225
 
221
- createPreviewConfig(targets) {
226
+ createPreviewBundler(context, transformers = []) {
227
+ const transformerContext = {
228
+ mode: 'prod'
229
+ };
230
+ const configs = this.createPreviewConfig(context.targets, transformers, transformerContext);
231
+ return new (_webpack4().WebpackBundler)(context.targets, configs, this.logger, _webpack().default);
232
+ }
233
+
234
+ createConfigs(targets, factory, transformers = [], transformerContext) {
222
235
  return targets.map(target => {
223
- return (0, _webpack2().configFactory)(target.entries, target.outputPath);
236
+ const baseConfig = factory(target.entries, target.outputPath);
237
+ const configMutator = new (_webpackModules().WebpackConfigMutator)(baseConfig);
238
+ const context = Object.assign({}, transformerContext, {
239
+ target
240
+ });
241
+ const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, context);
242
+ return afterMutation.raw;
224
243
  });
225
244
  }
226
245
 
246
+ createEmptyConfigs(targets, transformers = [], transformerContext) {
247
+ return this.createConfigs(targets, _webpack2().configFactory, transformers, transformerContext);
248
+ }
249
+
250
+ createPreviewConfig(targets, transformers = [], transformerContext) {
251
+ return this.createConfigs(targets, _webpackPreview().previewConfigFactory, transformers, transformerContext);
252
+ }
253
+
227
254
  createDevServerConfig(entry, rootPath, devServerID, publicRoot, publicPath, title) {
228
255
  return (0, _webpackDev().configFactory)(devServerID, rootPath, entry, publicRoot, publicPath, this.pubsub, title);
229
256
  }
@@ -245,6 +272,7 @@ _webpack3().WebpackAspect.addRuntime(WebpackMain);
245
272
  function runTransformersWithContext(config, transformers = [], context) {
246
273
  if (!Array.isArray(transformers)) return config;
247
274
  const newConfig = transformers.reduce((acc, transformer) => {
275
+ // @ts-ignore
248
276
  return transformer(acc, context);
249
277
  }, config);
250
278
  return newConfig;
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack.main.runtime.ts"],"names":["WebpackMain","constructor","pubsub","workspace","bundler","logger","createDevServer","context","transformers","config","createDevServerConfig","entry","path","id","rootPath","publicPath","title","configMutator","WebpackConfigMutator","transformerContext","mode","afterMutation","runTransformersWithContext","clone","WebpackDevServer","raw","webpack","WsDevServer","mergeConfig","target","source","createBundler","configs","createPreviewConfig","targets","mutatedConfigs","map","WebpackBundler","entries","outputPath","devServerID","publicRoot","provider","logPublisher","createLogger","WebpackAspect","MainRuntime","PubsubAspect","WorkspaceAspect","BundlerAspect","LoggerAspect","addRuntime","Array","isArray","newConfig","reduce","acc","transformer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AASA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;A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AM3BC,KAN2B,EAO3B;AACA,WAAO,iCAAuBwB,WAAvB,EAAoC1B,QAApC,EAA8CH,KAA9C,EAAqD8B,UAArD,EAAiE1B,UAAjE,EAA6E,KAAKb,MAAlF,EAA0Fc,KAA1F,CAAP;AACD;;AAOoB,eAAR0B,QAAQ,CAAC,CAACxC,MAAD,EAASC,SAAT,EAAoBC,OAApB,EAA6BC,MAA7B,CAAD,EAAyF;AAC5G,UAAMsC,YAAY,GAAGtC,MAAM,CAACuC,YAAP,CAAoBC,0BAAchC,EAAlC,CAArB;AACA,WAAO,IAAIb,WAAJ,CAAgBE,MAAhB,EAAwBC,SAAxB,EAAmCC,OAAnC,EAA4CuC,YAA5C,CAAP;AACD;;AAlFsB;;;gCAAZ3C,W,WA0EI,E;gCA1EJA,W,aA4EM8C,kB;gCA5EN9C,W,kBA6EW,CAAC+C,iBAAD,EAAeC,4BAAf,EAAgCC,wBAAhC,EAA+CC,sBAA/C,C;;AAQxBL,0BAAcM,UAAd,CAAyBnD,WAAzB;;AAEO,SAASsB,0BAAT,CACLb,MADK,EAELD,YAAwC,GAAG,EAFtC,EAGLD,OAHK,EAIiB;AACtB,MAAI,CAAC6C,KAAK,CAACC,OAAN,CAAc7C,YAAd,CAAL,EAAkC,OAAOC,MAAP;AAClC,QAAM6C,SAAS,GAAG9C,YAAY,CAAC+C,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;AAC1D,WAAOA,WAAW,CAACD,GAAD,EAAMjD,OAAN,CAAlB;AACD,GAFiB,EAEfE,MAFe,CAAlB;AAGA,SAAO6C,SAAP;AACD","sourcesContent":["import PubsubAspect, { PubsubMain } from '@teambit/pubsub';\nimport {\n BundlerAspect,\n BundlerContext,\n BundlerMain,\n DevServer,\n DevServerContext,\n BundlerMode,\n Target,\n} from '@teambit/bundler';\nimport { MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { merge } from 'webpack-merge';\nimport webpack from 'webpack';\nimport WsDevServer from 'webpack-dev-server';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\n\nimport { configFactory as devServerConfigFactory } from './config/webpack.dev.config';\nimport { configFactory as previewConfigFactory } from './config/webpack.config';\n\nimport { WebpackAspect } from './webpack.aspect';\nimport { WebpackBundler } from './webpack.bundler';\nimport { WebpackDevServer } from './webpack.dev-server';\n\nexport type WebpackConfigTransformContext = {\n mode: BundlerMode;\n};\nexport type WebpackConfigTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigTransformContext\n) => WebpackConfigMutator;\n\nexport class WebpackMain {\n constructor(\n /**\n * Pubsub extension.\n */\n public pubsub: PubsubMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * bundler extension.\n */\n private bundler: BundlerMain,\n\n /**\n * Logger extension\n */\n public logger: Logger\n ) {}\n\n /**\n * create an instance of bit-compliant webpack dev server for a set of components\n */\n createDevServer(context: DevServerContext, transformers: WebpackConfigTransformer[] = []): DevServer {\n const config = this.createDevServerConfig(\n context.entry,\n this.workspace.path,\n context.id,\n context.rootPath,\n context.publicPath,\n context.title\n ) as any;\n const configMutator = new WebpackConfigMutator(config);\n const transformerContext: WebpackConfigTransformContext = { mode: 'dev' };\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n // @ts-ignore - fix this\n return new WebpackDevServer(afterMutation.raw, webpack, WsDevServer);\n }\n\n mergeConfig(target: any, source: any): any {\n return merge(target, source);\n }\n\n createBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []) {\n const configs = this.createPreviewConfig(context.targets);\n const transformerContext: WebpackConfigTransformContext = { mode: 'prod' };\n const mutatedConfigs = configs.map((config) => {\n const configMutator = new WebpackConfigMutator(config);\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return afterMutation.raw;\n });\n return new WebpackBundler(context.targets, mutatedConfigs, this.logger, webpack);\n }\n\n private createPreviewConfig(targets: Target[]) {\n return targets.map((target) => {\n return previewConfigFactory(target.entries, target.outputPath);\n });\n }\n\n private createDevServerConfig(\n entry: string[],\n rootPath: string,\n devServerID: string,\n publicRoot: string,\n publicPath: string,\n title?: string\n ) {\n return devServerConfigFactory(devServerID, rootPath, entry, publicRoot, publicPath, this.pubsub, title);\n }\n\n static slots = [];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, WorkspaceAspect, BundlerAspect, LoggerAspect];\n\n static async provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]) {\n const logPublisher = logger.createLogger(WebpackAspect.id);\n return new WebpackMain(pubsub, workspace, bundler, logPublisher);\n }\n}\n\nWebpackAspect.addRuntime(WebpackMain);\n\nexport function runTransformersWithContext(\n config: WebpackConfigMutator,\n transformers: WebpackConfigTransformer[] = [],\n context: WebpackConfigTransformContext\n): WebpackConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"]}
1
+ {"version":3,"sources":["webpack.main.runtime.ts"],"names":["WebpackMain","constructor","pubsub","workspace","bundler","logger","createDevServer","context","transformers","config","createDevServerConfig","entry","path","id","rootPath","publicPath","title","configMutator","WebpackConfigMutator","transformerContext","mode","afterMutation","runTransformersWithContext","clone","WebpackDevServer","raw","webpack","WsDevServer","mergeConfig","target","source","createBundler","initialConfigs","configs","createEmptyConfigs","targets","WebpackBundler","createPreviewBundler","createPreviewConfig","createConfigs","factory","map","baseConfig","entries","outputPath","Object","assign","baseConfigFactory","previewConfigFactory","devServerID","publicRoot","provider","logPublisher","createLogger","WebpackAspect","MainRuntime","PubsubAspect","WorkspaceAspect","BundlerAspect","LoggerAspect","addRuntime","Array","isArray","newConfig","reduce","acc","transformer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AA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CAAP;AACD;;AAOoB,eAARmC,QAAQ,CAAC,CAACjD,MAAD,EAASC,SAAT,EAAoBC,OAApB,EAA6BC,MAA7B,CAAD,EAAyF;AAC5G,UAAM+C,YAAY,GAAG/C,MAAM,CAACgD,YAAP,CAAoBC,0BAAczC,EAAlC,CAArB;AACA,WAAO,IAAIb,WAAJ,CAAgBE,MAAhB,EAAwBC,SAAxB,EAAmCC,OAAnC,EAA4CgD,YAA5C,CAAP;AACD;;AAhHsB;;;gCAAZpD,W,WAwGI,E;gCAxGJA,W,aA0GMuD,kB;gCA1GNvD,W,kBA2GW,CAACwD,iBAAD,EAAeC,4BAAf,EAAgCC,wBAAhC,EAA+CC,sBAA/C,C;;AAQxBL,0BAAcM,UAAd,CAAyB5D,WAAzB;;AAEO,SAASsB,0BAAT,CACLb,MADK,EAELD,YAAiF,GAAG,EAF/E,EAGLD,OAHK,EAIiB;AACtB,MAAI,CAACsD,KAAK,CAACC,OAAN,CAActD,YAAd,CAAL,EAAkC,OAAOC,MAAP;AAClC,QAAMsD,SAAS,GAAGvD,YAAY,CAACwD,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;AAC1D;AACA,WAAOA,WAAW,CAACD,GAAD,EAAM1D,OAAN,CAAlB;AACD,GAHiB,EAGfE,MAHe,CAAlB;AAIA,SAAOsD,SAAP;AACD","sourcesContent":["import webpack, { Configuration } from 'webpack';\nimport PubsubAspect, { PubsubMain } from '@teambit/pubsub';\nimport {\n BundlerAspect,\n BundlerContext,\n BundlerMain,\n DevServer,\n DevServerContext,\n BundlerMode,\n Target,\n} from '@teambit/bundler';\nimport { MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { merge } from 'webpack-merge';\nimport WsDevServer from 'webpack-dev-server';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\n\nimport { configFactory as devServerConfigFactory } from './config/webpack.dev.config';\nimport { previewConfigFactory } from './config/webpack-preview.config';\nimport { configFactory as baseConfigFactory } from './config/webpack.config';\n\nimport { WebpackAspect } from './webpack.aspect';\nimport { WebpackBundler } from './webpack.bundler';\nimport { WebpackDevServer } from './webpack.dev-server';\n\nexport type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {\n target: Target;\n};\n\nexport type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext;\n\nexport type GlobalWebpackConfigTransformContext = {\n mode: BundlerMode;\n};\n\nexport type WebpackConfigTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigTransformContext\n) => WebpackConfigMutator;\n\nexport type WebpackConfigDevServerTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigDevServerTransformContext\n) => WebpackConfigMutator;\n\nexport class WebpackMain {\n constructor(\n /**\n * Pubsub extension.\n */\n public pubsub: PubsubMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * bundler extension.\n */\n private bundler: BundlerMain,\n\n /**\n * Logger extension\n */\n public logger: Logger\n ) {}\n\n /**\n * create an instance of bit-compliant webpack dev server for a set of components\n */\n createDevServer(context: DevServerContext, transformers: WebpackConfigTransformer[] = []): DevServer {\n const config = this.createDevServerConfig(\n context.entry,\n this.workspace.path,\n context.id,\n context.rootPath,\n context.publicPath,\n context.title\n ) as any;\n const configMutator = new WebpackConfigMutator(config);\n const transformerContext: GlobalWebpackConfigTransformContext = { mode: 'dev' };\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n // @ts-ignore - fix this\n return new WebpackDevServer(afterMutation.raw, webpack, WsDevServer);\n }\n\n mergeConfig(target: any, source: any): any {\n return merge(target, source);\n }\n\n createBundler(\n context: BundlerContext,\n transformers: WebpackConfigTransformer[] = [],\n initialConfigs?: webpack.Configuration[]\n ) {\n const transformerContext: GlobalWebpackConfigTransformContext = { mode: 'prod' };\n const configs = initialConfigs || this.createEmptyConfigs(context.targets, transformers, transformerContext);\n return new WebpackBundler(context.targets, configs, this.logger, webpack);\n }\n\n createPreviewBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []) {\n const transformerContext: GlobalWebpackConfigTransformContext = { mode: 'prod' };\n const configs = this.createPreviewConfig(context.targets, transformers, transformerContext);\n return new WebpackBundler(context.targets, configs, this.logger, webpack);\n }\n\n private createConfigs(\n targets: Target[],\n factory: (entries: string[], outputPath: string) => Configuration,\n transformers: WebpackConfigTransformer[] = [],\n transformerContext: GlobalWebpackConfigTransformContext\n ) {\n return targets.map((target) => {\n const baseConfig = factory(target.entries, target.outputPath);\n const configMutator = new WebpackConfigMutator(baseConfig);\n const context = Object.assign({}, transformerContext, { target });\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, context);\n return afterMutation.raw;\n });\n }\n\n private createEmptyConfigs(\n targets: Target[],\n transformers: WebpackConfigTransformer[] = [],\n transformerContext: GlobalWebpackConfigTransformContext\n ) {\n return this.createConfigs(targets, baseConfigFactory, transformers, transformerContext);\n }\n\n private createPreviewConfig(\n targets: Target[],\n transformers: WebpackConfigTransformer[] = [],\n transformerContext: GlobalWebpackConfigTransformContext\n ) {\n return this.createConfigs(targets, previewConfigFactory, transformers, transformerContext);\n }\n\n private createDevServerConfig(\n entry: string[],\n rootPath: string,\n devServerID: string,\n publicRoot: string,\n publicPath: string,\n title?: string\n ) {\n return devServerConfigFactory(devServerID, rootPath, entry, publicRoot, publicPath, this.pubsub, title);\n }\n\n static slots = [];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, WorkspaceAspect, BundlerAspect, LoggerAspect];\n\n static async provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]) {\n const logPublisher = logger.createLogger(WebpackAspect.id);\n return new WebpackMain(pubsub, workspace, bundler, logPublisher);\n }\n}\n\nWebpackAspect.addRuntime(WebpackMain);\n\nexport function runTransformersWithContext(\n config: WebpackConfigMutator,\n transformers: Array<WebpackConfigTransformer | WebpackConfigDevServerTransformer> = [],\n context: WebpackConfigTransformContext | WebpackConfigDevServerTransformContext\n): WebpackConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n // @ts-ignore\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"]}
package/index.ts CHANGED
@@ -1,4 +1,11 @@
1
- export type { WebpackMain, WebpackConfigTransformer, WebpackConfigTransformContext } from './webpack.main.runtime';
1
+ export type {
2
+ WebpackMain,
3
+ WebpackConfigTransformer,
4
+ WebpackConfigTransformContext,
5
+ WebpackConfigDevServerTransformContext,
6
+ GlobalWebpackConfigTransformContext,
7
+ WebpackConfigDevServerTransformer,
8
+ } from './webpack.main.runtime';
2
9
  export { runTransformersWithContext } from './webpack.main.runtime';
3
10
  export { WebpackAspect } from './webpack.aspect';
4
11
  export { WebpackDevServer } from './webpack.dev-server';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/webpack",
3
- "version": "0.0.547",
3
+ "version": "0.0.554",
4
4
  "homepage": "https://bit.dev/teambit/webpack/webpack",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.webpack",
8
8
  "name": "webpack",
9
- "version": "0.0.547"
9
+ "version": "0.0.554"
10
10
  },
11
11
  "dependencies": {
12
12
  "webpack": "5.51.1",
@@ -38,13 +38,13 @@
38
38
  "assert": "2.0.0",
39
39
  "@babel/runtime": "7.12.18",
40
40
  "core-js": "^3.0.0",
41
- "@teambit/webpack.modules.config-mutator": "0.0.108",
42
- "@teambit/bit-error": "0.0.366",
43
- "@teambit/bundler": "0.0.547",
44
- "@teambit/logger": "0.0.465",
45
- "@teambit/cli": "0.0.380",
46
- "@teambit/pubsub": "0.0.547",
47
- "@teambit/workspace": "0.0.547"
41
+ "@teambit/webpack.modules.config-mutator": "0.0.111",
42
+ "@teambit/bit-error": "0.0.371",
43
+ "@teambit/bundler": "0.0.554",
44
+ "@teambit/logger": "0.0.470",
45
+ "@teambit/cli": "0.0.385",
46
+ "@teambit/pubsub": "0.0.554",
47
+ "@teambit/workspace": "0.0.554"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/webpack": "5.28.0",
@@ -56,7 +56,7 @@
56
56
  "@types/node": "12.20.4"
57
57
  },
58
58
  "peerDependencies": {
59
- "@teambit/legacy": "1.0.169",
59
+ "@teambit/legacy": "1.0.171",
60
60
  "react-dom": "^16.8.0 || ^17.0.0",
61
61
  "react": "^16.8.0 || ^17.0.0"
62
62
  },
@@ -22,6 +22,7 @@ export class WebpackBundler implements Bundler {
22
22
  ) {}
23
23
 
24
24
  async run(): Promise<BundlerResult[]> {
25
+ const startTime = Date.now();
25
26
  const compilers = this.configs.map((config: any) => this.webpack(config));
26
27
  const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);
27
28
  const componentOutput = await mapSeries(compilers, (compiler: Compiler) => {
@@ -44,6 +45,8 @@ export class WebpackBundler implements Bundler {
44
45
  outputPath: stats.compilation.outputOptions.path,
45
46
  components,
46
47
  warnings: info.warnings,
48
+ startTime,
49
+ endTime: Date.now(),
47
50
  });
48
51
  });
49
52
  });
@@ -1,3 +1,4 @@
1
+ import webpack, { Configuration } from 'webpack';
1
2
  import PubsubAspect, { PubsubMain } from '@teambit/pubsub';
2
3
  import {
3
4
  BundlerAspect,
@@ -12,25 +13,37 @@ import { MainRuntime } from '@teambit/cli';
12
13
  import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
13
14
  import { Workspace, WorkspaceAspect } from '@teambit/workspace';
14
15
  import { merge } from 'webpack-merge';
15
- import webpack from 'webpack';
16
16
  import WsDevServer from 'webpack-dev-server';
17
17
  import { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
18
18
 
19
19
  import { configFactory as devServerConfigFactory } from './config/webpack.dev.config';
20
- import { configFactory as previewConfigFactory } from './config/webpack.config';
20
+ import { previewConfigFactory } from './config/webpack-preview.config';
21
+ import { configFactory as baseConfigFactory } from './config/webpack.config';
21
22
 
22
23
  import { WebpackAspect } from './webpack.aspect';
23
24
  import { WebpackBundler } from './webpack.bundler';
24
25
  import { WebpackDevServer } from './webpack.dev-server';
25
26
 
26
- export type WebpackConfigTransformContext = {
27
+ export type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {
28
+ target: Target;
29
+ };
30
+
31
+ export type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext;
32
+
33
+ export type GlobalWebpackConfigTransformContext = {
27
34
  mode: BundlerMode;
28
35
  };
36
+
29
37
  export type WebpackConfigTransformer = (
30
38
  config: WebpackConfigMutator,
31
39
  context: WebpackConfigTransformContext
32
40
  ) => WebpackConfigMutator;
33
41
 
42
+ export type WebpackConfigDevServerTransformer = (
43
+ config: WebpackConfigMutator,
44
+ context: WebpackConfigDevServerTransformContext
45
+ ) => WebpackConfigMutator;
46
+
34
47
  export class WebpackMain {
35
48
  constructor(
36
49
  /**
@@ -67,7 +80,7 @@ export class WebpackMain {
67
80
  context.title
68
81
  ) as any;
69
82
  const configMutator = new WebpackConfigMutator(config);
70
- const transformerContext: WebpackConfigTransformContext = { mode: 'dev' };
83
+ const transformerContext: GlobalWebpackConfigTransformContext = { mode: 'dev' };
71
84
  const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
72
85
  // @ts-ignore - fix this
73
86
  return new WebpackDevServer(afterMutation.raw, webpack, WsDevServer);
@@ -77,23 +90,53 @@ export class WebpackMain {
77
90
  return merge(target, source);
78
91
  }
79
92
 
80
- createBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []) {
81
- const configs = this.createPreviewConfig(context.targets);
82
- const transformerContext: WebpackConfigTransformContext = { mode: 'prod' };
83
- const mutatedConfigs = configs.map((config) => {
84
- const configMutator = new WebpackConfigMutator(config);
85
- const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
86
- return afterMutation.raw;
87
- });
88
- return new WebpackBundler(context.targets, mutatedConfigs, this.logger, webpack);
93
+ createBundler(
94
+ context: BundlerContext,
95
+ transformers: WebpackConfigTransformer[] = [],
96
+ initialConfigs?: webpack.Configuration[]
97
+ ) {
98
+ const transformerContext: GlobalWebpackConfigTransformContext = { mode: 'prod' };
99
+ const configs = initialConfigs || this.createEmptyConfigs(context.targets, transformers, transformerContext);
100
+ return new WebpackBundler(context.targets, configs, this.logger, webpack);
89
101
  }
90
102
 
91
- private createPreviewConfig(targets: Target[]) {
103
+ createPreviewBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []) {
104
+ const transformerContext: GlobalWebpackConfigTransformContext = { mode: 'prod' };
105
+ const configs = this.createPreviewConfig(context.targets, transformers, transformerContext);
106
+ return new WebpackBundler(context.targets, configs, this.logger, webpack);
107
+ }
108
+
109
+ private createConfigs(
110
+ targets: Target[],
111
+ factory: (entries: string[], outputPath: string) => Configuration,
112
+ transformers: WebpackConfigTransformer[] = [],
113
+ transformerContext: GlobalWebpackConfigTransformContext
114
+ ) {
92
115
  return targets.map((target) => {
93
- return previewConfigFactory(target.entries, target.outputPath);
116
+ const baseConfig = factory(target.entries, target.outputPath);
117
+ const configMutator = new WebpackConfigMutator(baseConfig);
118
+ const context = Object.assign({}, transformerContext, { target });
119
+ const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, context);
120
+ return afterMutation.raw;
94
121
  });
95
122
  }
96
123
 
124
+ private createEmptyConfigs(
125
+ targets: Target[],
126
+ transformers: WebpackConfigTransformer[] = [],
127
+ transformerContext: GlobalWebpackConfigTransformContext
128
+ ) {
129
+ return this.createConfigs(targets, baseConfigFactory, transformers, transformerContext);
130
+ }
131
+
132
+ private createPreviewConfig(
133
+ targets: Target[],
134
+ transformers: WebpackConfigTransformer[] = [],
135
+ transformerContext: GlobalWebpackConfigTransformContext
136
+ ) {
137
+ return this.createConfigs(targets, previewConfigFactory, transformers, transformerContext);
138
+ }
139
+
97
140
  private createDevServerConfig(
98
141
  entry: string[],
99
142
  rootPath: string,
@@ -120,11 +163,12 @@ WebpackAspect.addRuntime(WebpackMain);
120
163
 
121
164
  export function runTransformersWithContext(
122
165
  config: WebpackConfigMutator,
123
- transformers: WebpackConfigTransformer[] = [],
124
- context: WebpackConfigTransformContext
166
+ transformers: Array<WebpackConfigTransformer | WebpackConfigDevServerTransformer> = [],
167
+ context: WebpackConfigTransformContext | WebpackConfigDevServerTransformContext
125
168
  ): WebpackConfigMutator {
126
169
  if (!Array.isArray(transformers)) return config;
127
170
  const newConfig = transformers.reduce((acc, transformer) => {
171
+ // @ts-ignore
128
172
  return transformer(acc, context);
129
173
  }, config);
130
174
  return newConfig;