@nx/webpack 17.0.5 → 17.0.6

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.
Files changed (81) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +2 -2
  4. package/index.d.ts +1 -3
  5. package/index.js +2 -7
  6. package/migrations.json +0 -6
  7. package/package.json +5 -6
  8. package/src/executors/dev-server/dev-server.impl.js +17 -31
  9. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +3 -2
  10. package/src/executors/dev-server/lib/get-dev-server-config.js +26 -18
  11. package/src/executors/dev-server/schema.d.ts +8 -8
  12. package/src/executors/webpack/lib/get-webpack-config.d.ts +5 -0
  13. package/src/executors/webpack/lib/get-webpack-config.js +16 -0
  14. package/src/executors/webpack/lib/normalize-options.d.ts +2 -1
  15. package/src/executors/webpack/lib/normalize-options.js +53 -9
  16. package/src/executors/webpack/schema.d.ts +7 -10
  17. package/src/executors/webpack/schema.json +50 -30
  18. package/src/executors/webpack/webpack.impl.js +16 -36
  19. package/src/generators/configuration/configuration.d.ts +2 -3
  20. package/src/generators/configuration/configuration.js +23 -95
  21. package/src/generators/configuration/schema.d.ts +0 -1
  22. package/src/generators/configuration/schema.json +1 -1
  23. package/src/generators/init/init.d.ts +0 -1
  24. package/src/generators/init/init.js +23 -48
  25. package/src/generators/init/schema.d.ts +2 -4
  26. package/src/generators/init/schema.json +13 -18
  27. package/src/plugins/generate-package-json-plugin.d.ts +4 -6
  28. package/src/plugins/generate-package-json-plugin.js +14 -11
  29. package/src/utils/config.d.ts +6 -11
  30. package/src/utils/config.js +13 -48
  31. package/src/utils/get-client-environment.js +1 -4
  32. package/src/utils/module-federation/dependencies.js +3 -15
  33. package/src/utils/module-federation/get-remotes-for-host.d.ts +1 -2
  34. package/src/utils/module-federation/get-remotes-for-host.js +7 -11
  35. package/src/utils/module-federation/remotes.js +1 -1
  36. package/src/utils/module-federation/secondary-entry-points.js +1 -1
  37. package/src/utils/module-federation/typescript.js +9 -14
  38. package/src/utils/versions.d.ts +1 -1
  39. package/src/utils/versions.js +2 -2
  40. package/src/utils/webpack/custom-webpack.d.ts +2 -0
  41. package/src/utils/webpack/{resolve-user-defined-webpack-config.js → custom-webpack.js} +8 -14
  42. package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
  43. package/src/utils/webpack/interpolate-env-variables-to-index.js +1 -4
  44. package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
  45. package/src/utils/with-nx.d.ts +58 -4
  46. package/src/utils/with-nx.js +362 -22
  47. package/src/utils/with-web.d.ts +2 -2
  48. package/src/utils/with-web.js +488 -9
  49. package/plugin.d.ts +0 -1
  50. package/plugin.js +0 -5
  51. package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +0 -2
  52. package/src/migrations/update-17-2-1/webpack-config-setup.js +0 -31
  53. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +0 -8
  54. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +0 -31
  55. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +0 -5
  56. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +0 -318
  57. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +0 -5
  58. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +0 -372
  59. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +0 -53
  60. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +0 -78
  61. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +0 -1
  62. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +0 -35
  63. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +0 -3
  64. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +0 -42
  65. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +0 -4
  66. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +0 -148
  67. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +0 -73
  68. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +0 -117
  69. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +0 -216
  70. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +0 -2
  71. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +0 -17
  72. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +0 -48
  73. package/src/plugins/plugin.d.ts +0 -9
  74. package/src/plugins/plugin.js +0 -132
  75. package/src/utils/ensure-dependencies.d.ts +0 -6
  76. package/src/utils/ensure-dependencies.js +0 -27
  77. package/src/utils/has-plugin.d.ts +0 -2
  78. package/src/utils/has-plugin.js +0 -11
  79. package/src/utils/webpack/read-webpack-options.d.ts +0 -10
  80. package/src/utils/webpack/read-webpack-options.js +0 -41
  81. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +0 -3
@@ -1,53 +0,0 @@
1
- import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
2
- export declare function createLoaderFromCompiler(options: NormalizedNxWebpackPluginOptions): {
3
- test: RegExp;
4
- loader: string;
5
- exclude: RegExp;
6
- options: {
7
- cwd: string;
8
- emitDecoratorMetadata: boolean;
9
- isModern: boolean;
10
- isTest: boolean;
11
- envName: string;
12
- cacheDirectory: boolean;
13
- cacheCompression: boolean;
14
- };
15
- } | {
16
- test: RegExp;
17
- loader: string;
18
- exclude: RegExp;
19
- options: {
20
- jsc: {
21
- parser: {
22
- syntax: string;
23
- decorators: boolean;
24
- tsx: boolean;
25
- };
26
- transform: {
27
- react: {
28
- runtime: string;
29
- };
30
- };
31
- loose: boolean;
32
- };
33
- configFile?: undefined;
34
- transpileOnly?: undefined;
35
- experimentalWatchApi?: undefined;
36
- getCustomTransformers?: undefined;
37
- };
38
- } | {
39
- test: RegExp;
40
- loader: string;
41
- exclude: RegExp;
42
- options: {
43
- configFile: string;
44
- transpileOnly: boolean;
45
- experimentalWatchApi: boolean;
46
- getCustomTransformers: (program: any) => {
47
- before: any;
48
- after: any;
49
- afterDeclarations: any;
50
- };
51
- jsc?: undefined;
52
- };
53
- };
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLoaderFromCompiler = void 0;
4
- const path = require("path");
5
- const js_1 = require("@nx/js");
6
- function createLoaderFromCompiler(options) {
7
- switch (options.compiler) {
8
- case 'swc':
9
- return {
10
- test: /\.([jt])sx?$/,
11
- loader: require.resolve('swc-loader'),
12
- exclude: /node_modules/,
13
- options: {
14
- jsc: {
15
- parser: {
16
- syntax: 'typescript',
17
- decorators: true,
18
- tsx: true,
19
- },
20
- transform: {
21
- react: {
22
- runtime: 'automatic',
23
- },
24
- },
25
- loose: true,
26
- },
27
- },
28
- };
29
- case 'tsc':
30
- const { loadTsTransformers } = require('@nx/js');
31
- const { compilerPluginHooks, hasPlugin } = loadTsTransformers(options.transformers);
32
- return {
33
- test: /\.([jt])sx?$/,
34
- loader: require.resolve(`ts-loader`),
35
- exclude: /node_modules/,
36
- options: {
37
- configFile: options.tsConfig,
38
- transpileOnly: !hasPlugin,
39
- // https://github.com/TypeStrong/ts-loader/pull/685
40
- experimentalWatchApi: true,
41
- getCustomTransformers: (program) => ({
42
- before: compilerPluginHooks.beforeHooks.map((hook) => hook(program)),
43
- after: compilerPluginHooks.afterHooks.map((hook) => hook(program)),
44
- afterDeclarations: compilerPluginHooks.afterDeclarationsHooks.map((hook) => hook(program)),
45
- }),
46
- },
47
- };
48
- case 'babel':
49
- const tsConfig = (0, js_1.readTsConfig)(path.join(options.root, options.tsConfig));
50
- const babelConfig = {
51
- test: /\.([jt])sx?$/,
52
- loader: path.join(__dirname, '../../../utils/web-babel-loader'),
53
- exclude: /node_modules/,
54
- options: {
55
- cwd: path.join(options.root, options.sourceRoot),
56
- emitDecoratorMetadata: tsConfig.options.emitDecoratorMetadata,
57
- isModern: true,
58
- isTest: process.env.NX_CYPRESS_COMPONENT_TEST === 'true',
59
- envName: process.env.BABEL_ENV ?? process.env.NODE_ENV,
60
- cacheDirectory: true,
61
- cacheCompression: false,
62
- },
63
- };
64
- if (options.babelUpwardRootMode) {
65
- babelConfig.options['rootMode'] = 'upward';
66
- babelConfig.options['babelrc'] = true;
67
- }
68
- else {
69
- babelConfig.options['configFile'] = options.babelConfig
70
- ? path.join(options.root, options.babelConfig)
71
- : path.join(options.root, options.projectRoot, '.babelrc');
72
- }
73
- return babelConfig;
74
- default:
75
- return null;
76
- }
77
- }
78
- exports.createLoaderFromCompiler = createLoaderFromCompiler;
@@ -1 +0,0 @@
1
- export declare function getTerserEcmaVersion(projectRoot: string): 2020 | 5;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTerserEcmaVersion = void 0;
4
- const path = require("path");
5
- const fs = require("fs");
6
- const browserslist = require("browserslist");
7
- const VALID_BROWSERSLIST_FILES = ['.browserslistrc', 'browserslist'];
8
- const ES5_BROWSERS = [
9
- 'ie 10',
10
- 'ie 11',
11
- 'safari 11',
12
- 'safari 11.1',
13
- 'safari 12',
14
- 'safari 12.1',
15
- 'safari 13',
16
- 'ios_saf 13.0',
17
- 'ios_saf 13.3',
18
- ];
19
- function getTerserEcmaVersion(projectRoot) {
20
- let pathToBrowserslistFile = '';
21
- for (const browserslistFile of VALID_BROWSERSLIST_FILES) {
22
- const fullPathToFile = path.join(projectRoot, browserslistFile);
23
- if (fs.existsSync(fullPathToFile)) {
24
- pathToBrowserslistFile = fullPathToFile;
25
- break;
26
- }
27
- }
28
- if (!pathToBrowserslistFile) {
29
- return 2020;
30
- }
31
- const env = browserslist.loadConfig({ path: pathToBrowserslistFile });
32
- const browsers = browserslist(env);
33
- return browsers.some((b) => ES5_BROWSERS.includes(b)) ? 5 : 2020;
34
- }
35
- exports.getTerserEcmaVersion = getTerserEcmaVersion;
@@ -1,3 +0,0 @@
1
- import { WebpackPluginInstance } from 'webpack';
2
- import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
3
- export declare function instantiateScriptPlugins(options: NormalizedNxWebpackPluginOptions): WebpackPluginInstance[];
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instantiateScriptPlugins = void 0;
4
- const path = require("path");
5
- const hash_format_1 = require("../../../utils/hash-format");
6
- const scripts_webpack_plugin_1 = require("../../../utils/webpack/plugins/scripts-webpack-plugin");
7
- const normalize_entry_1 = require("../../../utils/webpack/normalize-entry");
8
- function instantiateScriptPlugins(options) {
9
- // process global scripts
10
- const globalScriptsByBundleName = (0, normalize_entry_1.normalizeExtraEntryPoints)(options.scripts || [], 'scripts').reduce((prev, curr) => {
11
- const bundleName = curr.bundleName;
12
- const resolvedPath = path.resolve(options.root, curr.input);
13
- const existingEntry = prev.find((el) => el.bundleName === bundleName);
14
- if (existingEntry) {
15
- existingEntry.paths.push(resolvedPath);
16
- }
17
- else {
18
- prev.push({
19
- inject: curr.inject,
20
- bundleName,
21
- paths: [resolvedPath],
22
- });
23
- }
24
- return prev;
25
- }, []);
26
- const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
27
- const plugins = [];
28
- // Add a new asset for each entry.
29
- globalScriptsByBundleName.forEach((script) => {
30
- const hash = script.inject ? hashFormat.script : '';
31
- const bundleName = script.bundleName;
32
- plugins.push(new scripts_webpack_plugin_1.ScriptsWebpackPlugin({
33
- name: bundleName,
34
- sourceMap: !!options.sourceMap,
35
- filename: `${path.basename(bundleName)}${hash}.js`,
36
- scripts: script.paths,
37
- basePath: options.sourceRoot,
38
- }));
39
- });
40
- return plugins;
41
- }
42
- exports.instantiateScriptPlugins = instantiateScriptPlugins;
@@ -1,4 +0,0 @@
1
- import { AssetGlobPattern, FileReplacement, NormalizedNxWebpackPluginOptions, NxWebpackPluginOptions } from '../nx-webpack-plugin-options';
2
- export declare function normalizeOptions(options: NxWebpackPluginOptions): NormalizedNxWebpackPluginOptions;
3
- export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string, projectRoot: string, resolveRelativePathsToProjectRoot?: boolean): AssetGlobPattern[];
4
- export declare function normalizeFileReplacements(root: string, fileReplacements: FileReplacement[]): FileReplacement[];
@@ -1,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeFileReplacements = exports.normalizeAssets = exports.normalizeOptions = void 0;
4
- const path_1 = require("path");
5
- const fs_1 = require("fs");
6
- const devkit_1 = require("@nx/devkit");
7
- function normalizeOptions(options) {
8
- const combinedPluginAndMaybeExecutorOptions = {};
9
- const isProd = process.env.NODE_ENV === 'production';
10
- const projectName = process.env.NX_TASK_TARGET_PROJECT;
11
- const targetName = process.env.NX_TASK_TARGET_TARGET;
12
- const configurationName = process.env.NX_TASK_TARGET_CONFIGURATION;
13
- // Since this is invoked by the executor, the graph has already been created and cached.
14
- const projectGraph = (0, devkit_1.readCachedProjectGraph)();
15
- const projectNode = projectGraph.nodes[projectName];
16
- const targetConfig = projectNode.data.targets[targetName];
17
- normalizeRelativePaths(projectNode.data.root, options);
18
- // Merge options from `@nx/webpack:webpack` into plugin options.
19
- // Options from `@nx/webpack:webpack` take precedence.
20
- const originalTargetOptions = targetConfig.options;
21
- if (configurationName) {
22
- Object.assign(originalTargetOptions, targetConfig.configurations?.[configurationName]);
23
- }
24
- // This could be called from dev-server which means we need to read `buildTarget` to get actual build options.
25
- // Otherwise, the options are passed from the `@nx/webpack:webpack` executor.
26
- if (originalTargetOptions.buildTarget) {
27
- const buildTargetOptions = targetConfig.options;
28
- if (configurationName) {
29
- Object.assign(buildTargetOptions, targetConfig.configurations?.[configurationName]);
30
- }
31
- Object.assign(combinedPluginAndMaybeExecutorOptions, options,
32
- // executor options take precedence (especially for overriding with CLI args)
33
- buildTargetOptions);
34
- }
35
- else {
36
- Object.assign(combinedPluginAndMaybeExecutorOptions, options,
37
- // executor options take precedence (especially for overriding with CLI args)
38
- originalTargetOptions);
39
- }
40
- const sourceRoot = projectNode.data.sourceRoot ?? projectNode.data.root;
41
- if (!options.main) {
42
- throw new Error(`Missing "main" option for the entry file. Set this option in your Nx webpack plugin.`);
43
- }
44
- return {
45
- ...combinedPluginAndMaybeExecutorOptions,
46
- assets: combinedPluginAndMaybeExecutorOptions.assets
47
- ? normalizeAssets(combinedPluginAndMaybeExecutorOptions.assets, devkit_1.workspaceRoot, sourceRoot, projectNode.data.root)
48
- : [],
49
- baseHref: combinedPluginAndMaybeExecutorOptions.baseHref ?? '/',
50
- commonChunk: combinedPluginAndMaybeExecutorOptions.commonChunk ?? true,
51
- compiler: combinedPluginAndMaybeExecutorOptions.compiler ?? 'babel',
52
- configurationName,
53
- deleteOutputPath: combinedPluginAndMaybeExecutorOptions.deleteOutputPath ?? true,
54
- extractCss: combinedPluginAndMaybeExecutorOptions.extractCss ?? true,
55
- fileReplacements: normalizeFileReplacements(devkit_1.workspaceRoot, combinedPluginAndMaybeExecutorOptions.fileReplacements),
56
- generateIndexHtml: combinedPluginAndMaybeExecutorOptions.generateIndexHtml ?? true,
57
- main: combinedPluginAndMaybeExecutorOptions.main,
58
- namedChunks: combinedPluginAndMaybeExecutorOptions.namedChunks ?? !isProd,
59
- optimization: combinedPluginAndMaybeExecutorOptions.optimization ?? isProd,
60
- outputFileName: combinedPluginAndMaybeExecutorOptions.outputFileName ?? 'main.js',
61
- outputHashing: combinedPluginAndMaybeExecutorOptions.outputHashing ??
62
- (isProd ? 'all' : 'none'),
63
- outputPath: combinedPluginAndMaybeExecutorOptions.outputPath,
64
- projectGraph,
65
- projectName,
66
- projectRoot: projectNode.data.root,
67
- root: devkit_1.workspaceRoot,
68
- runtimeChunk: combinedPluginAndMaybeExecutorOptions.runtimeChunk ?? true,
69
- scripts: combinedPluginAndMaybeExecutorOptions.scripts ?? [],
70
- sourceMap: combinedPluginAndMaybeExecutorOptions.sourceMap ?? !isProd,
71
- sourceRoot,
72
- styles: combinedPluginAndMaybeExecutorOptions.styles ?? [],
73
- target: combinedPluginAndMaybeExecutorOptions.target,
74
- targetName,
75
- vendorChunk: combinedPluginAndMaybeExecutorOptions.vendorChunk ?? !isProd,
76
- };
77
- }
78
- exports.normalizeOptions = normalizeOptions;
79
- function normalizeAssets(assets, root, sourceRoot, projectRoot, resolveRelativePathsToProjectRoot = true) {
80
- return assets.map((asset) => {
81
- if (typeof asset === 'string') {
82
- const assetPath = (0, devkit_1.normalizePath)(asset);
83
- const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
84
- const resolvedSourceRoot = (0, path_1.resolve)(root, sourceRoot);
85
- if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
86
- throw new Error(`The ${resolvedAssetPath} asset path must start with the project source root: ${sourceRoot}`);
87
- }
88
- const isDirectory = (0, fs_1.statSync)(resolvedAssetPath).isDirectory();
89
- const input = isDirectory
90
- ? resolvedAssetPath
91
- : (0, path_1.dirname)(resolvedAssetPath);
92
- const output = (0, path_1.relative)(resolvedSourceRoot, (0, path_1.resolve)(root, input));
93
- const glob = isDirectory ? '**/*' : (0, path_1.basename)(resolvedAssetPath);
94
- return {
95
- input,
96
- output,
97
- glob,
98
- };
99
- }
100
- else {
101
- if (asset.output.startsWith('..')) {
102
- throw new Error('An asset cannot be written to a location outside of the output path.');
103
- }
104
- const assetPath = (0, devkit_1.normalizePath)(asset.input);
105
- let resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
106
- if (resolveRelativePathsToProjectRoot && asset.input.startsWith('.')) {
107
- const resolvedProjectRoot = (0, path_1.resolve)(root, projectRoot);
108
- resolvedAssetPath = (0, path_1.resolve)(resolvedProjectRoot, assetPath);
109
- }
110
- return {
111
- ...asset,
112
- input: resolvedAssetPath,
113
- // Now we remove starting slash to make Webpack place it from the output root.
114
- output: asset.output.replace(/^\//, ''),
115
- };
116
- }
117
- });
118
- }
119
- exports.normalizeAssets = normalizeAssets;
120
- function normalizeFileReplacements(root, fileReplacements) {
121
- return fileReplacements
122
- ? fileReplacements.map((fileReplacement) => ({
123
- replace: (0, path_1.resolve)(root, fileReplacement.replace),
124
- with: (0, path_1.resolve)(root, fileReplacement.with),
125
- }))
126
- : [];
127
- }
128
- exports.normalizeFileReplacements = normalizeFileReplacements;
129
- function normalizeRelativePaths(projectRoot, options) {
130
- for (const [fieldName, fieldValue] of Object.entries(options)) {
131
- if (isRelativePath(fieldValue)) {
132
- options[fieldName] = (0, path_1.join)(projectRoot, fieldValue);
133
- }
134
- else if (Array.isArray(fieldValue)) {
135
- for (let i = 0; i < fieldValue.length; i++) {
136
- if (isRelativePath(fieldValue[i])) {
137
- fieldValue[i] = (0, path_1.join)(projectRoot, fieldValue[i]);
138
- }
139
- }
140
- }
141
- }
142
- }
143
- function isRelativePath(val) {
144
- return (typeof val === 'string' &&
145
- (val.startsWith('./') ||
146
- // Windows
147
- val.startsWith('.\\')));
148
- }
@@ -1,73 +0,0 @@
1
- import { getCSSModuleLocalIdent } from '../../../utils/get-css-module-local-ident';
2
- import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
3
- interface PostcssOptions {
4
- (loader: any): any;
5
- config?: string;
6
- }
7
- export declare function getCommonLoadersForCssModules(options: NormalizedNxWebpackPluginOptions, includePaths: string[]): ({
8
- loader: any;
9
- options?: undefined;
10
- } | {
11
- loader: string;
12
- options: {
13
- modules: {
14
- mode: string;
15
- getLocalIdent: typeof getCSSModuleLocalIdent;
16
- };
17
- importLoaders: number;
18
- implementation?: undefined;
19
- postcssOptions?: undefined;
20
- };
21
- } | {
22
- loader: string;
23
- options: {
24
- implementation: any;
25
- postcssOptions: PostcssOptions;
26
- modules?: undefined;
27
- importLoaders?: undefined;
28
- };
29
- })[];
30
- export declare function getCommonLoadersForGlobalCss(options: NormalizedNxWebpackPluginOptions, includePaths: string[]): ({
31
- loader: any;
32
- options?: undefined;
33
- } | {
34
- loader: string;
35
- options: {
36
- url: boolean;
37
- implementation?: undefined;
38
- postcssOptions?: undefined;
39
- };
40
- } | {
41
- loader: string;
42
- options: {
43
- implementation: any;
44
- postcssOptions: PostcssOptions;
45
- url?: undefined;
46
- };
47
- })[];
48
- export declare function getCommonLoadersForGlobalStyle(options: NormalizedNxWebpackPluginOptions, includePaths: string[]): ({
49
- loader: any;
50
- options: {
51
- esModule: boolean;
52
- url?: undefined;
53
- implementation?: undefined;
54
- postcssOptions?: undefined;
55
- };
56
- } | {
57
- loader: string;
58
- options: {
59
- url: boolean;
60
- esModule?: undefined;
61
- implementation?: undefined;
62
- postcssOptions?: undefined;
63
- };
64
- } | {
65
- loader: string;
66
- options: {
67
- implementation: any;
68
- postcssOptions: PostcssOptions;
69
- esModule?: undefined;
70
- url?: undefined;
71
- };
72
- })[];
73
- export {};
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommonLoadersForGlobalStyle = exports.getCommonLoadersForGlobalCss = exports.getCommonLoadersForCssModules = void 0;
4
- const path = require("path");
5
- const autoprefixer = require("autoprefixer");
6
- const postcssImports = require("postcss-import");
7
- const MiniCssExtractPlugin = require("mini-css-extract-plugin");
8
- const get_css_module_local_ident_1 = require("../../../utils/get-css-module-local-ident");
9
- const hash_format_1 = require("../../../utils/hash-format");
10
- const postcss_cli_resources_1 = require("../../../utils/webpack/plugins/postcss-cli-resources");
11
- function getCommonLoadersForCssModules(options, includePaths) {
12
- // load component css as raw strings
13
- return [
14
- {
15
- loader: options.extractCss
16
- ? MiniCssExtractPlugin.loader
17
- : require.resolve('style-loader'),
18
- },
19
- {
20
- loader: require.resolve('css-loader'),
21
- options: {
22
- modules: {
23
- mode: 'local',
24
- getLocalIdent: get_css_module_local_ident_1.getCSSModuleLocalIdent,
25
- },
26
- importLoaders: 1,
27
- },
28
- },
29
- {
30
- loader: require.resolve('postcss-loader'),
31
- options: {
32
- implementation: require('postcss'),
33
- postcssOptions: postcssOptionsCreator(options, {
34
- includePaths,
35
- forCssModules: true,
36
- }),
37
- },
38
- },
39
- ];
40
- }
41
- exports.getCommonLoadersForCssModules = getCommonLoadersForCssModules;
42
- function getCommonLoadersForGlobalCss(options, includePaths) {
43
- return [
44
- {
45
- loader: options.extractCss
46
- ? MiniCssExtractPlugin.loader
47
- : require.resolve('style-loader'),
48
- },
49
- { loader: require.resolve('css-loader'), options: { url: false } },
50
- {
51
- loader: require.resolve('postcss-loader'),
52
- options: {
53
- implementation: require('postcss'),
54
- postcssOptions: postcssOptionsCreator(options, {
55
- includePaths,
56
- }),
57
- },
58
- },
59
- ];
60
- }
61
- exports.getCommonLoadersForGlobalCss = getCommonLoadersForGlobalCss;
62
- function getCommonLoadersForGlobalStyle(options, includePaths) {
63
- return [
64
- {
65
- loader: options.extractCss
66
- ? MiniCssExtractPlugin.loader
67
- : require.resolve('style-loader'),
68
- options: { esModule: true },
69
- },
70
- { loader: require.resolve('css-loader'), options: { url: false } },
71
- {
72
- loader: require.resolve('postcss-loader'),
73
- options: {
74
- implementation: require('postcss'),
75
- postcssOptions: postcssOptionsCreator(options, {
76
- includePaths,
77
- }),
78
- },
79
- },
80
- ];
81
- }
82
- exports.getCommonLoadersForGlobalStyle = getCommonLoadersForGlobalStyle;
83
- function postcssOptionsCreator(options, { includePaths, forCssModules = false, }) {
84
- const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
85
- // PostCSS options depend on the webpack loader, but we need to set the `config` path as a string due to this check:
86
- // https://github.com/webpack-contrib/postcss-loader/blob/0d342b1/src/utils.js#L36
87
- const postcssOptions = (loader) => ({
88
- map: options.sourceMap &&
89
- options.sourceMap !== 'hidden' && {
90
- inline: true,
91
- annotation: false,
92
- },
93
- plugins: [
94
- postcssImports({
95
- addModulesDirectories: includePaths,
96
- resolve: (url) => (url.startsWith('~') ? url.slice(1) : url),
97
- }),
98
- ...(forCssModules
99
- ? []
100
- : [
101
- (0, postcss_cli_resources_1.PostcssCliResources)({
102
- baseHref: options.baseHref,
103
- deployUrl: options.deployUrl,
104
- loader,
105
- filename: `[name]${hashFormat.file}.[ext]`,
106
- }),
107
- autoprefixer(),
108
- ]),
109
- ],
110
- });
111
- // If a path to postcssConfig is passed in, set it for app and all libs, otherwise
112
- // use automatic detection.
113
- if (typeof options.postcssConfig === 'string') {
114
- postcssOptions.config = path.join(options.root, options.postcssConfig);
115
- }
116
- return postcssOptions;
117
- }