@compiled/webpack-loader 0.8.5 → 0.9.0

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.
@@ -1 +1 @@
1
- export declare const styles: import("@compiled/react").CSSProps;
1
+ export declare const styles: import("@compiled/react").CSSProps<unknown>;
@@ -1 +1 @@
1
- export declare const styles: import("@compiled/react").CSSProps;
1
+ export declare const styles: import("@compiled/react").CSSProps<unknown>;
@@ -30,7 +30,7 @@ let hasErrored = false;
30
30
  * @returns
31
31
  */
32
32
  function getLoaderOptions(context) {
33
- const { bake = true, extract = false, importReact = undefined, nonce = undefined, resolve = {}, extensions = undefined, babelPlugins = [], [extract_plugin_1.pluginName]: isPluginEnabled = false, } = typeof context.getOptions === 'undefined'
33
+ const { bake = true, extract = false, importReact = undefined, nonce = undefined, resolve = {}, extensions = undefined, parserBabelPlugins = [], transformerBabelPlugins = [], [extract_plugin_1.pluginName]: isPluginEnabled = false, ssr = false, } = typeof context.getOptions === 'undefined'
34
34
  ? // Webpack v4 flow
35
35
  (0, loader_utils_1.getOptions)(context)
36
36
  : // Webpack v5 flow
@@ -55,12 +55,18 @@ function getLoaderOptions(context) {
55
55
  extensions: {
56
56
  type: 'array',
57
57
  },
58
- babelPlugins: {
58
+ parserBabelPlugins: {
59
+ type: 'array',
60
+ },
61
+ transformerBabelPlugins: {
59
62
  type: 'array',
60
63
  },
61
64
  [extract_plugin_1.pluginName]: {
62
65
  type: 'boolean',
63
66
  },
67
+ ssr: {
68
+ type: 'boolean',
69
+ },
64
70
  },
65
71
  });
66
72
  return {
@@ -70,8 +76,10 @@ function getLoaderOptions(context) {
70
76
  nonce,
71
77
  resolve,
72
78
  extensions,
73
- babelPlugins,
79
+ parserBabelPlugins,
80
+ transformerBabelPlugins,
74
81
  [extract_plugin_1.pluginName]: isPluginEnabled,
82
+ ssr,
75
83
  };
76
84
  }
77
85
  /**
@@ -81,27 +89,29 @@ function getLoaderOptions(context) {
81
89
  * @param code
82
90
  */
83
91
  async function compiledLoader(code) {
84
- var _a, _b, _c;
92
+ var _a, _b, _c, _d, _e;
85
93
  const callback = this.async();
86
- // Bail early if Compiled isn't in the module.
87
- if (code.indexOf('@compiled/react') === -1) {
94
+ // Bail early if Compiled isn't in the module or we're looking at compiled runtime code
95
+ if (code.indexOf('@compiled/react') === -1 ||
96
+ this.resourcePath.includes('/node_modules/@compiled/react')) {
88
97
  return callback(null, code);
89
98
  }
90
99
  try {
91
100
  const includedFiles = [];
92
- const _d = getLoaderOptions(this), { resolve } = _d, options = __rest(_d, ["resolve"]);
101
+ const _f = getLoaderOptions(this), { resolve } = _f, options = __rest(_f, ["resolve"]);
93
102
  // Transform to an AST using the local babel config.
94
103
  const ast = await (0, core_1.parseAsync)(code, {
95
104
  filename: this.resourcePath,
96
105
  caller: { name: 'compiled' },
97
106
  rootMode: 'upward-optional',
107
+ plugins: (_a = options.transformerBabelPlugins) !== null && _a !== void 0 ? _a : undefined,
98
108
  });
99
109
  // Setup the default resolver, where webpack will merge any passed in options with the default
100
110
  // resolve configuration. Ideally, we use this.getResolve({ ...resolve, useSyncFileSystemCalls: true, })
101
111
  // However, it does not work correctly when in development mode :/
102
112
  const resolver = enhanced_resolve_1.ResolverFactory.createResolver(Object.assign(Object.assign(Object.assign({
103
113
  // @ts-expect-error
104
- fileSystem: new enhanced_resolve_1.CachedInputFileSystem(fs_1.default, 4000) }, ((_b = (_a = this._compilation) === null || _a === void 0 ? void 0 : _a.options.resolve) !== null && _b !== void 0 ? _b : {})), resolve), {
114
+ fileSystem: new enhanced_resolve_1.CachedInputFileSystem(fs_1.default, 4000) }, ((_c = (_b = this._compilation) === null || _b === void 0 ? void 0 : _b.options.resolve) !== null && _c !== void 0 ? _c : {})), resolve), {
105
115
  // This makes the resolver invoke the callback synchronously
106
116
  useSyncFileSystemCalls: true }));
107
117
  // Transform using the Compiled Babel Plugin - we deliberately turn off using the local config.
@@ -111,10 +121,12 @@ async function compiledLoader(code) {
111
121
  sourceMaps: true,
112
122
  filename: this.resourcePath,
113
123
  plugins: [
124
+ ...((_d = options.transformerBabelPlugins) !== null && _d !== void 0 ? _d : []),
114
125
  options.extract && [
115
126
  '@compiled/babel-plugin-strip-runtime',
116
127
  {
117
128
  styleSheetPath: `@compiled/webpack-loader/css-loader!@compiled/webpack-loader/css-loader/${extract_plugin_1.styleSheetName}.css`,
129
+ compiledRequireExclude: options.ssr,
118
130
  },
119
131
  ],
120
132
  options.bake && [
@@ -131,7 +143,7 @@ async function compiledLoader(code) {
131
143
  includedFiles.forEach((file) => {
132
144
  this.addDependency((0, path_1.normalize)(file));
133
145
  });
134
- callback(null, (result === null || result === void 0 ? void 0 : result.code) || '', (_c = result === null || result === void 0 ? void 0 : result.map) !== null && _c !== void 0 ? _c : undefined);
146
+ callback(null, (result === null || result === void 0 ? void 0 : result.code) || '', (_e = result === null || result === void 0 ? void 0 : result.map) !== null && _e !== void 0 ? _e : undefined);
135
147
  }
136
148
  catch (e) {
137
149
  // @ts-expect-error Not checking for error type
@@ -1 +1 @@
1
- {"version":3,"file":"compiled-loader.js","sourceRoot":"","sources":["../src/compiled-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,+BAA0C;AAE1C,sCAAgE;AAChE,2CAAyD;AACzD,uDAA0E;AAC1E,+CAA0C;AAG1C,qDAA8D;AAG9D,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,MAAM,EACJ,IAAI,GAAG,IAAI,EACX,OAAO,GAAG,KAAK,EACf,WAAW,GAAG,SAAS,EACvB,KAAK,GAAG,SAAS,EACjB,OAAO,GAAG,EAAE,EACZ,UAAU,GAAG,SAAS,EACtB,YAAY,GAAG,EAAE,EACjB,CAAC,2BAAU,CAAC,EAAE,eAAe,GAAG,KAAK,GACtC,GAA0B,OAAO,OAAO,CAAC,UAAU,KAAK,WAAW;QAClE,CAAC,CAAC,kBAAkB;YA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AAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,2BAAU,CAAC,EAAE;QAC1D,IAAI,CAAC,SAAS,CACZ,IAAA,mBAAW,EAAC,gBAAgB,CAAC,CAC3B,gLAAgL,CACjL,CACF,CAAC;QAEF,4FAA4F;QAC5F,UAAU,GAAG,IAAI,CAAC;KACnB;AACH,CAAC;AAZD,sBAYC"}
@@ -39,7 +39,7 @@ const getCSSAssets = (assets) => {
39
39
  *
40
40
  * @param compiler
41
41
  */
42
- const forceCSSIntoOneStyleSheet = (compiler) => {
42
+ const forceCSSIntoOneStyleSheet = (compiler, options) => {
43
43
  const cacheGroup = {
44
44
  compiledCSS: {
45
45
  name: exports.styleSheetName,
@@ -48,6 +48,7 @@ const forceCSSIntoOneStyleSheet = (compiler) => {
48
48
  // We merge only CSS from Compiled.
49
49
  test: /css-loader\/compiled-css\.css$/,
50
50
  enforce: true,
51
+ priority: Infinity,
51
52
  },
52
53
  };
53
54
  if (!compiler.options.optimization) {
@@ -61,7 +62,7 @@ const forceCSSIntoOneStyleSheet = (compiler) => {
61
62
  if (!compiler.options.optimization.splitChunks.cacheGroups) {
62
63
  compiler.options.optimization.splitChunks.cacheGroups = {};
63
64
  }
64
- Object.assign(compiler.options.optimization.splitChunks.cacheGroups, cacheGroup);
65
+ Object.assign(compiler.options.optimization.splitChunks.cacheGroups, options.cacheGroupExclude ? {} : cacheGroup);
65
66
  };
66
67
  /**
67
68
  * Pushes a new loader onto the compiler.
@@ -101,7 +102,7 @@ class CompiledExtractPlugin {
101
102
  apply(compiler) {
102
103
  const { RawSource } = (0, utils_2.getSources)(compiler);
103
104
  pushNodeModulesExtractLoader(compiler, __classPrivateFieldGet(this, _CompiledExtractPlugin_options, "f"));
104
- forceCSSIntoOneStyleSheet(compiler);
105
+ forceCSSIntoOneStyleSheet(compiler, __classPrivateFieldGet(this, _CompiledExtractPlugin_options, "f"));
105
106
  compiler.hooks.compilation.tap(exports.pluginName, (compilation) => {
106
107
  (0, utils_2.setPluginConfiguredOption)(compilation.options.module.rules, exports.pluginName);
107
108
  (0, utils_2.getOptimizeAssetsHook)(compiler, compilation).tap(exports.pluginName, (assets) => {
@@ -1 +1 @@
1
- {"version":3,"file":"extract-plugin.js","sourceRoot":"","sources":["../src/extract-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAAqC;AACrC,2CAAyD;AAIzD,mCAKiB;AAEJ,QAAA,UAAU,GAAG,uBAAuB,CAAC;AACrC,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CAAC,MAA6B,EAAE,EAAE;IACrD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACvB,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACpB,OAAO,SAAS,CAAC,QAAQ,CAAC,GAAG,sBAAc,MAAM,CAAC,CAAC;IACrD,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACpF,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,yBAAyB,GAAG,CAAC,QAAkB,EAAE,EAAE;IACvD,MAAM,UAAU,GAAG;QACjB,WAAW,EAAE;YACX,IAAI,EAAE,sBAAc;YACpB,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE,KAAK;YACb,mCAAmC;YACnC,IAAI,EAAE,gCAAgC;YACtC,OAAO,EAAE,IAAI;SACd;KACF,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE;QAClC,QAAQ,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAC;KACpC;IAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE;QAC9C,QAAQ,CAAC,OAA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AAE;YACzD,IAAA,iCAAyB,EAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAU,CAAC,CAAC;YAExE,IAAA,6BAAqB,EAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,kBAAU,EAAE,CAAC,MAAM,EAAE,EAAE;gBACtE,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;gBACvC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;oBAC1B,OAAO;iBACR;gBAED,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;gBAC1B,MAAM,QAAQ,GAAG,IAAA,8BAAsB,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACtD,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,IAAA,UAAI,EAAC,QAAQ,CAAC,CAAC,CAAC;gBAEhD,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9BD,sDA8BC"}
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { PluginItem } from '@babel/core';
1
2
  import type { ParserPlugin } from '@babel/parser';
2
3
  import type { ResolveOptions, RuleSetCondition } from 'webpack';
3
4
  import type { pluginName } from './extract-plugin';
@@ -32,13 +33,26 @@ export interface CompiledLoaderOptions {
32
33
  */
33
34
  extensions?: string[];
34
35
  /**
35
- * List of babel plugins to be applied to evaluated files
36
+ * List of transformer babel plugins to be applied to evaluated files
37
+ *
38
+ * See the [babel docs](https://babeljs.io/docs/en/plugins/#transform-plugins)
36
39
  */
37
- babelPlugins?: ParserPlugin[];
40
+ transformerBabelPlugins?: PluginItem[];
41
+ /**
42
+ * List of parse babel plugins to be applied to evaluated files
43
+ *
44
+ * See the [babel docs](https://babeljs.io/docs/en/plugins/#syntax-plugins)
45
+ */
46
+ parserBabelPlugins?: ParserPlugin[];
38
47
  /**
39
48
  * Set to true if CompiledExtractPlugin has been set up correctly
40
49
  */
41
50
  [pluginName]?: boolean;
51
+ /**
52
+ * Build in a node environment.
53
+ * Defaults to `false`.
54
+ */
55
+ ssr?: boolean;
42
56
  }
43
57
  export interface CompiledExtractPluginOptions {
44
58
  /**
@@ -56,4 +70,9 @@ export interface CompiledExtractPluginOptions {
56
70
  * See: https://webpack.js.org/configuration/module/#condition
57
71
  */
58
72
  nodeModulesExclude?: RuleSetCondition;
73
+ /**
74
+ * When set will prevent additional cacheGroup chunk to be created.
75
+ * Eg. This may be required in SSR to prevent side-effects
76
+ */
77
+ cacheGroupExclude?: boolean;
59
78
  }
package/dist/utils.js CHANGED
@@ -1,6 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSources = exports.getOptimizeAssetsHook = exports.getAssetSourceContents = exports.setPluginConfiguredOption = void 0;
4
+ /**
5
+ * Helper function to set plugin configured option on the @compiled/webpack-loader
6
+ *
7
+ * @param use
8
+ * @param pluginName
9
+ */
10
+ const setOptionOnCompiledWebpackLoader = (use, pluginName) => {
11
+ if (!use || !Array.isArray(use) || !use.length) {
12
+ return;
13
+ }
14
+ for (const nestedUse of use) {
15
+ if (typeof nestedUse === 'object' && nestedUse.loader === '@compiled/webpack-loader') {
16
+ const { options } = nestedUse;
17
+ if (options !== undefined && typeof options === 'object' && options.extract !== undefined) {
18
+ options[pluginName] = true;
19
+ }
20
+ }
21
+ }
22
+ };
4
23
  /**
5
24
  * Sets an option on the plugin config to tell loaders that the plugin has been configured.
6
25
  * Bundling will throw if this option is missing (i.e. consumers did not setup correctly).
@@ -10,34 +29,17 @@ exports.getSources = exports.getOptimizeAssetsHook = exports.getAssetSourceConte
10
29
  * @returns
11
30
  */
12
31
  const setPluginConfiguredOption = (rules, pluginName) => {
13
- for (const rule of rules) {
14
- const use = rule.use;
15
- if (!use || typeof use === 'string') {
16
- continue;
17
- }
18
- if (Array.isArray(use)) {
19
- if (!use.length) {
20
- continue;
21
- }
22
- for (const nestedUse of use) {
23
- if (typeof nestedUse !== 'object' || nestedUse.loader !== '@compiled/webpack-loader') {
24
- continue;
25
- }
26
- const { options } = nestedUse;
27
- if (!options || typeof options !== 'object' || !options.extract) {
28
- continue;
29
- }
30
- options[pluginName] = true;
32
+ var _a;
33
+ for (const r of rules) {
34
+ const rule = r;
35
+ const nestedRules = (_a = rule.oneOf) !== null && _a !== void 0 ? _a : rule.rules;
36
+ if (nestedRules) {
37
+ for (const nestedRule of nestedRules) {
38
+ setOptionOnCompiledWebpackLoader(nestedRule.use, pluginName);
31
39
  }
32
40
  }
33
41
  else {
34
- if (typeof use === 'object' && use.loader === '@compiled/webpack-loader') {
35
- const { options } = use;
36
- if (!options || typeof options !== 'object' || !options.extract) {
37
- continue;
38
- }
39
- options[pluginName] = true;
40
- }
42
+ setOptionOnCompiledWebpackLoader(rule.use, pluginName);
41
43
  }
42
44
  }
43
45
  };
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACI,MAAM,yBAAyB,GAAG,CACvC,KAA8B,EAC9B,UAAkB,EACZ,EAAE;IACR,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,MAAM,GAAG,GAAI,IAAoB,CAAC,GAAG,CAAC;QACtC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YACnC,SAAS;SACV;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;gBACf,SAAS;aACV;YACD,KAAK,MAAM,SAAS,IAAI,GAAG,EAAE;gBAC3B,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,0BAA0B,EAAE;oBACpF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QAC/B,iBAAiB;QACjB,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC;IAEnC,OAAO;QACL,GAAG,EAAE,CAAC,UAAkB,EAAE,QAAqD,EAAE,EAAE;YACjF,cAAc,CAAC,GAAG,CAChB,UAAU;gBACR,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC;oBACE,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,WAAW,CAAC,kCAAkC;iBACtD,EACL,QAAQ,CACT,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,qBAAqB,yBA6BhC;AAEF;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,QAAkB,EAAkB,EAAE;IAC/D,MAAM,EAAE,OAAO,EAAE;IACf,iBAAiB;IACjB,QAAQ,CAAC,OAAO;QAChB,iBAAiB;QACjB,EAAE,CAAC;IAEL,OAAO;IACL,iBAAiB;IACjB,OAAO;QACP,iBAAiB;QACjB,OAAO,CAAC,iBAAiB,CAAC,CAC3B,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,UAAU,cAarB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/webpack-loader",
3
- "version": "0.8.5",
3
+ "version": "0.9.0",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "homepage": "https://compiledcssinjs.com/docs/pkg-webpack-loader",
6
6
  "bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
@@ -20,25 +20,25 @@
20
20
  "src"
21
21
  ],
22
22
  "dependencies": {
23
- "@babel/core": "^7.17.5",
24
- "@compiled/babel-plugin": "^0.14.0",
25
- "@compiled/babel-plugin-strip-runtime": "^0.14.0",
26
- "@compiled/css": "^0.8.2",
27
- "@compiled/react": "0.10.4",
23
+ "@babel/core": "^7.17.10",
24
+ "@compiled/babel-plugin": "^0.16.0",
25
+ "@compiled/babel-plugin-strip-runtime": "^0.16.0",
26
+ "@compiled/css": "^0.8.3",
27
+ "@compiled/react": "0.11.0",
28
28
  "@compiled/utils": "^0.6.16",
29
- "enhanced-resolve": "^5.8.3",
29
+ "enhanced-resolve": "^5.9.3",
30
30
  "loader-utils": "^2.0.2",
31
31
  "webpack-sources": "^3.2.3"
32
32
  },
33
33
  "devDependencies": {
34
- "babel-loader": "^8.2.3",
35
- "css-loader": "^6.7.0",
36
- "memfs": "^3.4.1",
34
+ "babel-loader": "^8.2.4",
35
+ "css-loader": "^6.7.1",
36
+ "memfs": "^3.4.4",
37
37
  "mini-css-extract-plugin": "^1.6.2",
38
38
  "react": "^17.0.2",
39
39
  "ts-node": "^10.7.0",
40
- "tsconfig-paths": "^3.13.0",
41
- "webpack": "^5.69.1"
40
+ "tsconfig-paths": "^3.14.1",
41
+ "webpack": "^5.71.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "webpack": ">= 4.46.0"
@@ -26,6 +26,14 @@ describe('CompiledExtractPlugin', () => {
26
26
  ]);
27
27
  }, 10000);
28
28
 
29
+ it('should not generate a single style sheet if cacheGroup is disabled', async () => {
30
+ const actual = await bundle(join(fixturesPath, 'local-styles.tsx'), {
31
+ disableCacheGroup: true,
32
+ });
33
+
34
+ expect(actual[assetName]).toBe(undefined);
35
+ }, 10000);
36
+
29
37
  it('extracts local styles', async () => {
30
38
  const actual = await bundle(join(fixturesPath, 'local-styles.tsx'));
31
39
 
@@ -10,13 +10,20 @@ import type { ResolveOptions } from '../index';
10
10
  export interface BundleOptions {
11
11
  extract?: boolean;
12
12
  disableExtractPlugin?: boolean;
13
+ disableCacheGroup?: boolean;
13
14
  mode: 'development' | 'production';
14
15
  resolve?: ResolveOptions;
15
16
  }
16
17
 
17
18
  export function bundle(
18
19
  entry: string,
19
- { extract = false, disableExtractPlugin = false, mode, resolve = {} }: BundleOptions
20
+ {
21
+ extract = false,
22
+ disableExtractPlugin = false,
23
+ disableCacheGroup = false,
24
+ mode,
25
+ resolve = {},
26
+ }: BundleOptions
20
27
  ): Promise<Record<string, string>> {
21
28
  const outputPath = join(__dirname, 'dist');
22
29
  const compiler = webpack({
@@ -62,7 +69,9 @@ export function bundle(
62
69
  },
63
70
  plugins: [
64
71
  new MiniCssExtractPlugin({ filename: 'static/[name].css' }),
65
- ...(disableExtractPlugin ? [] : [new CompiledExtractPlugin()]),
72
+ ...(disableExtractPlugin
73
+ ? []
74
+ : [new CompiledExtractPlugin(disableCacheGroup ? { cacheGroupExclude: true } : {})]),
66
75
  ],
67
76
  resolve: {
68
77
  alias: {
@@ -26,8 +26,10 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
26
26
  nonce = undefined,
27
27
  resolve = {},
28
28
  extensions = undefined,
29
- babelPlugins = [],
29
+ parserBabelPlugins = [],
30
+ transformerBabelPlugins = [],
30
31
  [pluginName]: isPluginEnabled = false,
32
+ ssr = false,
31
33
  }: CompiledLoaderOptions = typeof context.getOptions === 'undefined'
32
34
  ? // Webpack v4 flow
33
35
  getOptions(context)
@@ -53,12 +55,18 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
53
55
  extensions: {
54
56
  type: 'array',
55
57
  },
56
- babelPlugins: {
58
+ parserBabelPlugins: {
59
+ type: 'array',
60
+ },
61
+ transformerBabelPlugins: {
57
62
  type: 'array',
58
63
  },
59
64
  [pluginName]: {
60
65
  type: 'boolean',
61
66
  },
67
+ ssr: {
68
+ type: 'boolean',
69
+ },
62
70
  },
63
71
  });
64
72
 
@@ -69,8 +77,10 @@ function getLoaderOptions(context: LoaderContext<CompiledLoaderOptions>) {
69
77
  nonce,
70
78
  resolve,
71
79
  extensions,
72
- babelPlugins,
80
+ parserBabelPlugins,
81
+ transformerBabelPlugins,
73
82
  [pluginName]: isPluginEnabled,
83
+ ssr,
74
84
  };
75
85
  }
76
86
 
@@ -86,8 +96,11 @@ export default async function compiledLoader(
86
96
  ): Promise<void> {
87
97
  const callback = this.async();
88
98
 
89
- // Bail early if Compiled isn't in the module.
90
- if (code.indexOf('@compiled/react') === -1) {
99
+ // Bail early if Compiled isn't in the module or we're looking at compiled runtime code
100
+ if (
101
+ code.indexOf('@compiled/react') === -1 ||
102
+ this.resourcePath.includes('/node_modules/@compiled/react')
103
+ ) {
91
104
  return callback(null, code);
92
105
  }
93
106
 
@@ -100,6 +113,7 @@ export default async function compiledLoader(
100
113
  filename: this.resourcePath,
101
114
  caller: { name: 'compiled' },
102
115
  rootMode: 'upward-optional',
116
+ plugins: options.transformerBabelPlugins ?? undefined,
103
117
  });
104
118
 
105
119
  // Setup the default resolver, where webpack will merge any passed in options with the default
@@ -121,10 +135,12 @@ export default async function compiledLoader(
121
135
  sourceMaps: true,
122
136
  filename: this.resourcePath,
123
137
  plugins: [
138
+ ...(options.transformerBabelPlugins ?? []),
124
139
  options.extract && [
125
140
  '@compiled/babel-plugin-strip-runtime',
126
141
  {
127
142
  styleSheetPath: `@compiled/webpack-loader/css-loader!@compiled/webpack-loader/css-loader/${styleSheetName}.css`,
143
+ compiledRequireExclude: options.ssr,
128
144
  },
129
145
  ],
130
146
  options.bake && [
@@ -35,7 +35,7 @@ const getCSSAssets = (assets: Compilation['assets']) => {
35
35
  *
36
36
  * @param compiler
37
37
  */
38
- const forceCSSIntoOneStyleSheet = (compiler: Compiler) => {
38
+ const forceCSSIntoOneStyleSheet = (compiler: Compiler, options: CompiledExtractPluginOptions) => {
39
39
  const cacheGroup = {
40
40
  compiledCSS: {
41
41
  name: styleSheetName,
@@ -44,6 +44,7 @@ const forceCSSIntoOneStyleSheet = (compiler: Compiler) => {
44
44
  // We merge only CSS from Compiled.
45
45
  test: /css-loader\/compiled-css\.css$/,
46
46
  enforce: true,
47
+ priority: Infinity,
47
48
  },
48
49
  };
49
50
 
@@ -61,7 +62,10 @@ const forceCSSIntoOneStyleSheet = (compiler: Compiler) => {
61
62
  compiler.options.optimization.splitChunks.cacheGroups = {};
62
63
  }
63
64
 
64
- Object.assign(compiler.options.optimization.splitChunks.cacheGroups, cacheGroup);
65
+ Object.assign(
66
+ compiler.options.optimization.splitChunks.cacheGroups,
67
+ options.cacheGroupExclude ? {} : cacheGroup
68
+ );
65
69
  };
66
70
 
67
71
  /**
@@ -110,7 +114,7 @@ export class CompiledExtractPlugin {
110
114
  const { RawSource } = getSources(compiler);
111
115
 
112
116
  pushNodeModulesExtractLoader(compiler, this.#options);
113
- forceCSSIntoOneStyleSheet(compiler);
117
+ forceCSSIntoOneStyleSheet(compiler, this.#options);
114
118
 
115
119
  compiler.hooks.compilation.tap(pluginName, (compilation) => {
116
120
  setPluginConfiguredOption(compilation.options.module.rules, pluginName);
package/src/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { PluginItem } from '@babel/core';
1
2
  import type { ParserPlugin } from '@babel/parser';
2
3
  import type { ResolveOptions, RuleSetCondition } from 'webpack';
3
4
 
@@ -41,14 +42,29 @@ export interface CompiledLoaderOptions {
41
42
  extensions?: string[];
42
43
 
43
44
  /**
44
- * List of babel plugins to be applied to evaluated files
45
+ * List of transformer babel plugins to be applied to evaluated files
46
+ *
47
+ * See the [babel docs](https://babeljs.io/docs/en/plugins/#transform-plugins)
45
48
  */
46
- babelPlugins?: ParserPlugin[];
49
+ transformerBabelPlugins?: PluginItem[];
50
+
51
+ /**
52
+ * List of parse babel plugins to be applied to evaluated files
53
+ *
54
+ * See the [babel docs](https://babeljs.io/docs/en/plugins/#syntax-plugins)
55
+ */
56
+ parserBabelPlugins?: ParserPlugin[];
47
57
 
48
58
  /**
49
59
  * Set to true if CompiledExtractPlugin has been set up correctly
50
60
  */
51
61
  [pluginName]?: boolean;
62
+
63
+ /**
64
+ * Build in a node environment.
65
+ * Defaults to `false`.
66
+ */
67
+ ssr?: boolean;
52
68
  }
53
69
 
54
70
  export interface CompiledExtractPluginOptions {
@@ -69,4 +85,10 @@ export interface CompiledExtractPluginOptions {
69
85
  * See: https://webpack.js.org/configuration/module/#condition
70
86
  */
71
87
  nodeModulesExclude?: RuleSetCondition;
88
+
89
+ /**
90
+ * When set will prevent additional cacheGroup chunk to be created.
91
+ * Eg. This may be required in SSR to prevent side-effects
92
+ */
93
+ cacheGroupExclude?: boolean;
72
94
  }
package/src/utils.ts CHANGED
@@ -1,5 +1,26 @@
1
1
  import type { Compilation as CompilationType, Compiler, sources, RuleSetRule } from 'webpack';
2
2
 
3
+ /**
4
+ * Helper function to set plugin configured option on the @compiled/webpack-loader
5
+ *
6
+ * @param use
7
+ * @param pluginName
8
+ */
9
+ const setOptionOnCompiledWebpackLoader = (use: RuleSetRule['use'], pluginName: string) => {
10
+ if (!use || !Array.isArray(use) || !use.length) {
11
+ return;
12
+ }
13
+
14
+ for (const nestedUse of use) {
15
+ if (typeof nestedUse === 'object' && nestedUse.loader === '@compiled/webpack-loader') {
16
+ const { options } = nestedUse;
17
+ if (options !== undefined && typeof options === 'object' && options.extract !== undefined) {
18
+ options[pluginName] = true;
19
+ }
20
+ }
21
+ }
22
+ };
23
+
3
24
  /**
4
25
  * Sets an option on the plugin config to tell loaders that the plugin has been configured.
5
26
  * Bundling will throw if this option is missing (i.e. consumers did not setup correctly).
@@ -12,33 +33,15 @@ export const setPluginConfiguredOption = (
12
33
  rules: (RuleSetRule | '...')[],
13
34
  pluginName: string
14
35
  ): void => {
15
- for (const rule of rules) {
16
- const use = (rule as RuleSetRule).use;
17
- if (!use || typeof use === 'string') {
18
- continue;
19
- }
20
- if (Array.isArray(use)) {
21
- if (!use.length) {
22
- continue;
23
- }
24
- for (const nestedUse of use) {
25
- if (typeof nestedUse !== 'object' || nestedUse.loader !== '@compiled/webpack-loader') {
26
- continue;
27
- }
28
- const { options } = nestedUse;
29
- if (!options || typeof options !== 'object' || !options.extract) {
30
- continue;
31
- }
32
- options[pluginName] = true;
36
+ for (const r of rules) {
37
+ const rule = r as RuleSetRule;
38
+ const nestedRules = rule.oneOf ?? rule.rules;
39
+ if (nestedRules) {
40
+ for (const nestedRule of nestedRules) {
41
+ setOptionOnCompiledWebpackLoader(nestedRule.use, pluginName);
33
42
  }
34
43
  } else {
35
- if (typeof use === 'object' && use.loader === '@compiled/webpack-loader') {
36
- const { options } = use;
37
- if (!options || typeof options !== 'object' || !options.extract) {
38
- continue;
39
- }
40
- options[pluginName] = true;
41
- }
44
+ setOptionOnCompiledWebpackLoader(rule.use, pluginName);
42
45
  }
43
46
  }
44
47
  };