@rushstack/heft-web-rig 0.19.8 → 0.19.10

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 (33) hide show
  1. package/LICENSE +24 -24
  2. package/README.md +35 -35
  3. package/package.json +10 -10
  4. package/profiles/app/config/heft.json +68 -68
  5. package/profiles/app/config/jest.config.json +3 -3
  6. package/profiles/app/config/rush-project.json +12 -12
  7. package/profiles/app/config/sass.json +65 -65
  8. package/profiles/app/config/typescript.json +98 -98
  9. package/profiles/app/includes/eslint/mixins/friendly-locals.js +6 -6
  10. package/profiles/app/includes/eslint/mixins/packlets.js +6 -6
  11. package/profiles/app/includes/eslint/mixins/react.js +6 -6
  12. package/profiles/app/includes/eslint/mixins/tsdoc.js +6 -6
  13. package/profiles/app/includes/eslint/patch/custom-config-package-names.js +4 -4
  14. package/profiles/app/includes/eslint/patch/modern-module-resolution.js +4 -4
  15. package/profiles/app/includes/eslint/profile/web-app.js +6 -6
  16. package/profiles/app/tsconfig-base.json +34 -34
  17. package/profiles/app/webpack-base.config.js +39 -39
  18. package/profiles/library/config/api-extractor-task.json +27 -27
  19. package/profiles/library/config/heft.json +68 -68
  20. package/profiles/library/config/jest.config.json +3 -3
  21. package/profiles/library/config/rush-project.json +12 -12
  22. package/profiles/library/config/sass.json +65 -65
  23. package/profiles/library/config/typescript.json +98 -98
  24. package/profiles/library/includes/eslint/mixins/friendly-locals.js +6 -6
  25. package/profiles/library/includes/eslint/mixins/packlets.js +6 -6
  26. package/profiles/library/includes/eslint/mixins/react.js +6 -6
  27. package/profiles/library/includes/eslint/mixins/tsdoc.js +6 -6
  28. package/profiles/library/includes/eslint/patch/custom-config-package-names.js +4 -4
  29. package/profiles/library/includes/eslint/patch/modern-module-resolution.js +4 -4
  30. package/profiles/library/includes/eslint/profile/web-app.js +6 -6
  31. package/profiles/library/tsconfig-base.json +34 -34
  32. package/profiles/library/webpack-base.config.js +50 -50
  33. package/shared/webpack-base.config.js +273 -273
@@ -1,273 +1,273 @@
1
- 'use strict';
2
-
3
- const webpack = require('webpack');
4
- const path = require('path');
5
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
- const { DefinePlugin } = webpack;
7
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
8
- const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
9
- const { merge, mergeWithCustomize, mergeWithRules, unique } = require('webpack-merge');
10
- const sass = require('sass');
11
- const autoprefixer = require('autoprefixer');
12
-
13
- /**
14
- * If the "--production" command-line parameter is specified when invoking Heft, then the
15
- * "production" function parameter will be true. You can use this to enable bundling optimizations.
16
- */
17
- function createWebpackConfig({ env, argv, projectRoot, configOverride, extractCssInProduction }) {
18
- const { production } = env;
19
-
20
- const defaultArgs = {
21
- // Documentation: https://webpack.js.org/configuration/mode/
22
- mode: production ? 'production' : 'development',
23
- resolve: {
24
- extensions: ['.mjs', '.js', '.json']
25
- },
26
- output: production
27
- ? {
28
- chunkFilename: '[name].[contenthash].js',
29
- filename: '[name].[contenthash].js',
30
- sourceMapFilename: '[name].[contenthash].js.map'
31
- }
32
- : {},
33
- module: {
34
- rules: [
35
- {
36
- // The source-map-loader extracts existing source maps from all JavaScript entries. This includes both
37
- // inline source maps as well as those linked via URL. All source map data is passed to Webpack for
38
- // processing as per a chosen source map style specified by the devtool option in webpack.config.js.
39
- // https://www.npmjs.com/package/source-map-loader
40
- test: /\.js$/,
41
-
42
- // Include source maps from other library projects in the monorepo workspace,
43
- // but exclude source maps for external NPM packages. Webpack tests the fs.realPathSync() path,
44
- // so external packages will be under "common/temp/node_modules/.pnpm/".
45
- exclude: /[\\/]\.pnpm[\\/]/,
46
-
47
- enforce: 'pre',
48
- use: [
49
- {
50
- loader: require.resolve('source-map-loader')
51
- }
52
- ]
53
- },
54
-
55
- {
56
- // CSS/SASS INPUT FORMATS
57
- //
58
- // We recommend the newer .scss file format because its syntax is a proper superset of familiar CSS.
59
- // The older .sass syntax is also accepted for backwards compatibility.
60
- //
61
- // The Sass documentation is here: https://sass-lang.com/documentation/syntax
62
- //
63
- // File extensions Sass Autoprefixer CSS modules .d.ts
64
- // ----------------- ---- ------------ ------------- -----
65
- // *.scss: YES YES YES YES (recommended)
66
- // *.sass: YES YES YES YES (deprecated)
67
- // *.global.scss: YES YES NO NO
68
- // *.global.sass: YES YES NO NO (deprecated)
69
- // *.css: NO YES NO NO
70
- //
71
- // If you want .css syntax but with CSS modules, use the .scss file extension; its syntax
72
- // is a superset of CSS. (There's a small performance penalty for applying Sass to a CSS file,
73
- // but the extra syntax validation justifies that cost.)
74
- //
75
- // COMPILATION STRATEGY
76
- //
77
- // - Sass compilation: handled by Webpack
78
- // - .d.ts generation: handled by @rushstack/heft-sass-plugin, configured using config/sass.json
79
- // - Autoprefixer: handled by Webpack
80
- // - CSS modules: handled by Webpack
81
- test: /\.(scss|sass|css)$/,
82
- exclude: /node_modules/,
83
- use: [
84
- // "For production builds it's recommended to extract the CSS from your bundle being able to
85
- // use parallel loading of CSS/JS resources later on. This can be achieved by using the
86
- // mini-css-extract-plugin, because it creates separate css files."
87
- //
88
- // "For development mode (including webpack-dev-server) you can use style-loader, because it injects
89
- // CSS into the DOM using multiple <style></style> and works faster."
90
- //
91
- // "WARNING: Do not use style-loader and mini-css-extract-plugin together."
92
- production && extractCssInProduction
93
- ? {
94
- loader: MiniCssExtractPlugin.loader
95
- }
96
- : {
97
- // Generates JavaScript code that injects CSS styles into the DOM at runtime.
98
- // The default configuration creates <style> elements from JS strings
99
- // https://www.npmjs.com/package/style-loader
100
- loader: require.resolve('style-loader')
101
- },
102
-
103
- {
104
- // Translates CSS into CommonJS
105
- // https://www.npmjs.com/package/css-loader
106
- loader: require.resolve('css-loader'),
107
- options: {
108
- // 0 => no loaders (default);
109
- // 1 => postcss-loader;
110
- // 2 => postcss-loader, sass-loader
111
- importLoaders: 2,
112
-
113
- // Enable CSS modules: https://github.com/css-modules/css-modules
114
- modules: {
115
- // The "auto" setting has a confusing design:
116
- // - "false" disables CSS modules, i.e. ":local" and ":global" selectors can't be used at all
117
- // - "true" means magically disable CSS modules if the file extension isn't like ".module.css"
118
- // or ".module.scss"
119
- // - a lambda disables CSS modules only if the lambda returns false; the function parameter is
120
- // the resource path
121
- // - a RegExp disables CSS modules only if the resource path does not match the RegExp
122
- //
123
- // NOTE: Counterintuitively, if you instead set "modules=true" then CSS modules are enabled
124
- // without magic, equivalent to "auto: () => true" instead of "auto: true"
125
- //
126
- // DEFAULT: "true" (i.e. path based magic)
127
- auto: (resourcePath) => {
128
- // Enable CSS modules...
129
- const useCssModules =
130
- // ...UNLESS the filename opts out using a file extension like "filename.global.scss"
131
- !/\.global\.\w+$/i.test(resourcePath) &&
132
- // ...UNLESS this is a .css file.
133
- !/\.css$/i.test(resourcePath);
134
- return useCssModules;
135
- },
136
-
137
- // This setting has no effect unless CSS modules is enabled. Possible values:
138
- // - "local": global CSS by default, overridable using the ":local" selector
139
- // - "global": local CSS by default, overridable using the ":global" selector
140
- // - "pure": requires selectors to contain at least one local class or id
141
- // - a lambda that returns the mode string; the function parameter is the resource path
142
- //
143
- // DEFAULT: "local"
144
- mode: 'local',
145
-
146
- // Set this to true if you want to be able to reference the global declarations using import statements
147
- // similar to local CSS modules
148
- //
149
- // DEFAULT: false
150
- // exportGlobals: true,
151
-
152
- // Provide a recognizable class/module names for developers
153
- //
154
- // DEFAULT: "[hash:base64]"
155
- localIdentName: production ? '[hash:base64]' : '[local]__[hash:base64:5]'
156
- },
157
-
158
- sourceMap: !production
159
- }
160
- }
161
- ],
162
-
163
- // Nested rules are applied after the parent rules.
164
- // https://webpack.js.org/configuration/module/#nested-rules
165
- rules: [
166
- {
167
- // Prevent postcss-loader and sass-loader from processing the .css file extension
168
- test: /\.(scss|sass)$/,
169
-
170
- use: [
171
- {
172
- // PostCSS is a general-purpose CSS transformer; however, we prefer to avoid custom CSS syntaxes
173
- // and only use the standard SASS syntax. Thus postcss-loader is used here only to apply the popular
174
- // "autoprefixer" plugin improves browser compatibility by generating vendor prefixes.
175
- // https://www.npmjs.com/package/postcss-loader
176
- loader: require.resolve('postcss-loader'),
177
- options: {
178
- postcssOptions: {
179
- plugins: [
180
- // https://www.npmjs.com/package/autoprefixer
181
- autoprefixer
182
- ]
183
- },
184
-
185
- sourceMap: !production
186
- }
187
- },
188
- {
189
- // Compiles SASS syntax into CSS
190
- // https://www.npmjs.com/package/sass-loader
191
- loader: require.resolve('sass-loader'),
192
-
193
- options: {
194
- implementation: sass,
195
- sassOptions: {
196
- includePaths: [path.resolve(__dirname, 'node_modules')]
197
- },
198
-
199
- sourceMap: !production
200
- }
201
- }
202
- ]
203
- }
204
- ]
205
- },
206
-
207
- {
208
- test: /\.(jpeg|jpg|png|gif|svg|ico)$/,
209
- // Allows import/require() to be used with an asset file. The file will be copied to the output folder,
210
- // and the import statement will return its URL.
211
- // https://webpack.js.org/guides/asset-modules/#resource-assets
212
- type: 'asset/resource'
213
- }
214
- ]
215
- },
216
- devServer: {
217
- host: 'localhost',
218
- port: 8080
219
- },
220
- // See here for documentation: https://webpack.js.org/configuration/devtool
221
- devtool: production ? undefined : 'eval-source-map',
222
- optimization: {
223
- minimize: !!production,
224
- nodeEnv: production ? 'production' : 'development',
225
- minimizer: [
226
- new CssMinimizerPlugin({
227
- minimizerOptions: {
228
- preset: ['default', { discardComments: { removeAll: !!production } }]
229
- }
230
- }),
231
- // This magic constant indicates the minimizer defaults
232
- // https://webpack.js.org/configuration/optimization/#optimizationminimizer
233
- '...'
234
- ]
235
- },
236
- plugins: [
237
- // See here for documentation: https://webpack.js.org/plugins/mini-css-extract-plugin/
238
- new MiniCssExtractPlugin({
239
- filename: '[name].[contenthash].css'
240
- }),
241
-
242
- // See here for documentation: https://webpack.js.org/plugins/define-plugin/
243
- new DefinePlugin({
244
- DEBUG: !production
245
- }),
246
-
247
- process.env.REPORT ? new BundleAnalyzerPlugin({ analyzerMode: 'static' }) : undefined
248
- ]
249
- };
250
-
251
- let result = mergeWithCustomize({
252
- // Remove duplicate of HtmlWebpackPlugin
253
- // this allows projects to override the default rig behavior if applicable (ex. when targeting older browsers)
254
- customizeArray: unique(
255
- 'plugins',
256
- ['HtmlWebpackPlugin'],
257
- (plugin) => plugin && plugin.constructor && plugin.constructor.name
258
- )
259
- })(defaultArgs, configOverride);
260
-
261
- // Remove undefined/null plugins
262
- if (Array.isArray(result.plugins)) {
263
- result.plugins = result.plugins.filter(Boolean);
264
- }
265
-
266
- return result;
267
- }
268
-
269
- createWebpackConfig.merge = merge;
270
- createWebpackConfig.mergeWithCustomize = mergeWithCustomize;
271
- createWebpackConfig.mergeWithRules = mergeWithRules;
272
-
273
- module.exports = createWebpackConfig;
1
+ 'use strict';
2
+
3
+ const webpack = require('webpack');
4
+ const path = require('path');
5
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
+ const { DefinePlugin } = webpack;
7
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
8
+ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
9
+ const { merge, mergeWithCustomize, mergeWithRules, unique } = require('webpack-merge');
10
+ const sass = require('sass');
11
+ const autoprefixer = require('autoprefixer');
12
+
13
+ /**
14
+ * If the "--production" command-line parameter is specified when invoking Heft, then the
15
+ * "production" function parameter will be true. You can use this to enable bundling optimizations.
16
+ */
17
+ function createWebpackConfig({ env, argv, projectRoot, configOverride, extractCssInProduction }) {
18
+ const { production } = env;
19
+
20
+ const defaultArgs = {
21
+ // Documentation: https://webpack.js.org/configuration/mode/
22
+ mode: production ? 'production' : 'development',
23
+ resolve: {
24
+ extensions: ['.mjs', '.js', '.json']
25
+ },
26
+ output: production
27
+ ? {
28
+ chunkFilename: '[name].[contenthash].js',
29
+ filename: '[name].[contenthash].js',
30
+ sourceMapFilename: '[name].[contenthash].js.map'
31
+ }
32
+ : {},
33
+ module: {
34
+ rules: [
35
+ {
36
+ // The source-map-loader extracts existing source maps from all JavaScript entries. This includes both
37
+ // inline source maps as well as those linked via URL. All source map data is passed to Webpack for
38
+ // processing as per a chosen source map style specified by the devtool option in webpack.config.js.
39
+ // https://www.npmjs.com/package/source-map-loader
40
+ test: /\.js$/,
41
+
42
+ // Include source maps from other library projects in the monorepo workspace,
43
+ // but exclude source maps for external NPM packages. Webpack tests the fs.realPathSync() path,
44
+ // so external packages will be under "common/temp/node_modules/.pnpm/".
45
+ exclude: /[\\/]\.pnpm[\\/]/,
46
+
47
+ enforce: 'pre',
48
+ use: [
49
+ {
50
+ loader: require.resolve('source-map-loader')
51
+ }
52
+ ]
53
+ },
54
+
55
+ {
56
+ // CSS/SASS INPUT FORMATS
57
+ //
58
+ // We recommend the newer .scss file format because its syntax is a proper superset of familiar CSS.
59
+ // The older .sass syntax is also accepted for backwards compatibility.
60
+ //
61
+ // The Sass documentation is here: https://sass-lang.com/documentation/syntax
62
+ //
63
+ // File extensions Sass Autoprefixer CSS modules .d.ts
64
+ // ----------------- ---- ------------ ------------- -----
65
+ // *.scss: YES YES YES YES (recommended)
66
+ // *.sass: YES YES YES YES (deprecated)
67
+ // *.global.scss: YES YES NO NO
68
+ // *.global.sass: YES YES NO NO (deprecated)
69
+ // *.css: NO YES NO NO
70
+ //
71
+ // If you want .css syntax but with CSS modules, use the .scss file extension; its syntax
72
+ // is a superset of CSS. (There's a small performance penalty for applying Sass to a CSS file,
73
+ // but the extra syntax validation justifies that cost.)
74
+ //
75
+ // COMPILATION STRATEGY
76
+ //
77
+ // - Sass compilation: handled by Webpack
78
+ // - .d.ts generation: handled by @rushstack/heft-sass-plugin, configured using config/sass.json
79
+ // - Autoprefixer: handled by Webpack
80
+ // - CSS modules: handled by Webpack
81
+ test: /\.(scss|sass|css)$/,
82
+ exclude: /node_modules/,
83
+ use: [
84
+ // "For production builds it's recommended to extract the CSS from your bundle being able to
85
+ // use parallel loading of CSS/JS resources later on. This can be achieved by using the
86
+ // mini-css-extract-plugin, because it creates separate css files."
87
+ //
88
+ // "For development mode (including webpack-dev-server) you can use style-loader, because it injects
89
+ // CSS into the DOM using multiple <style></style> and works faster."
90
+ //
91
+ // "WARNING: Do not use style-loader and mini-css-extract-plugin together."
92
+ production && extractCssInProduction
93
+ ? {
94
+ loader: MiniCssExtractPlugin.loader
95
+ }
96
+ : {
97
+ // Generates JavaScript code that injects CSS styles into the DOM at runtime.
98
+ // The default configuration creates <style> elements from JS strings
99
+ // https://www.npmjs.com/package/style-loader
100
+ loader: require.resolve('style-loader')
101
+ },
102
+
103
+ {
104
+ // Translates CSS into CommonJS
105
+ // https://www.npmjs.com/package/css-loader
106
+ loader: require.resolve('css-loader'),
107
+ options: {
108
+ // 0 => no loaders (default);
109
+ // 1 => postcss-loader;
110
+ // 2 => postcss-loader, sass-loader
111
+ importLoaders: 2,
112
+
113
+ // Enable CSS modules: https://github.com/css-modules/css-modules
114
+ modules: {
115
+ // The "auto" setting has a confusing design:
116
+ // - "false" disables CSS modules, i.e. ":local" and ":global" selectors can't be used at all
117
+ // - "true" means magically disable CSS modules if the file extension isn't like ".module.css"
118
+ // or ".module.scss"
119
+ // - a lambda disables CSS modules only if the lambda returns false; the function parameter is
120
+ // the resource path
121
+ // - a RegExp disables CSS modules only if the resource path does not match the RegExp
122
+ //
123
+ // NOTE: Counterintuitively, if you instead set "modules=true" then CSS modules are enabled
124
+ // without magic, equivalent to "auto: () => true" instead of "auto: true"
125
+ //
126
+ // DEFAULT: "true" (i.e. path based magic)
127
+ auto: (resourcePath) => {
128
+ // Enable CSS modules...
129
+ const useCssModules =
130
+ // ...UNLESS the filename opts out using a file extension like "filename.global.scss"
131
+ !/\.global\.\w+$/i.test(resourcePath) &&
132
+ // ...UNLESS this is a .css file.
133
+ !/\.css$/i.test(resourcePath);
134
+ return useCssModules;
135
+ },
136
+
137
+ // This setting has no effect unless CSS modules is enabled. Possible values:
138
+ // - "local": global CSS by default, overridable using the ":local" selector
139
+ // - "global": local CSS by default, overridable using the ":global" selector
140
+ // - "pure": requires selectors to contain at least one local class or id
141
+ // - a lambda that returns the mode string; the function parameter is the resource path
142
+ //
143
+ // DEFAULT: "local"
144
+ mode: 'local',
145
+
146
+ // Set this to true if you want to be able to reference the global declarations using import statements
147
+ // similar to local CSS modules
148
+ //
149
+ // DEFAULT: false
150
+ // exportGlobals: true,
151
+
152
+ // Provide a recognizable class/module names for developers
153
+ //
154
+ // DEFAULT: "[hash:base64]"
155
+ localIdentName: production ? '[hash:base64]' : '[local]__[hash:base64:5]'
156
+ },
157
+
158
+ sourceMap: !production
159
+ }
160
+ }
161
+ ],
162
+
163
+ // Nested rules are applied after the parent rules.
164
+ // https://webpack.js.org/configuration/module/#nested-rules
165
+ rules: [
166
+ {
167
+ // Prevent postcss-loader and sass-loader from processing the .css file extension
168
+ test: /\.(scss|sass)$/,
169
+
170
+ use: [
171
+ {
172
+ // PostCSS is a general-purpose CSS transformer; however, we prefer to avoid custom CSS syntaxes
173
+ // and only use the standard SASS syntax. Thus postcss-loader is used here only to apply the popular
174
+ // "autoprefixer" plugin improves browser compatibility by generating vendor prefixes.
175
+ // https://www.npmjs.com/package/postcss-loader
176
+ loader: require.resolve('postcss-loader'),
177
+ options: {
178
+ postcssOptions: {
179
+ plugins: [
180
+ // https://www.npmjs.com/package/autoprefixer
181
+ autoprefixer
182
+ ]
183
+ },
184
+
185
+ sourceMap: !production
186
+ }
187
+ },
188
+ {
189
+ // Compiles SASS syntax into CSS
190
+ // https://www.npmjs.com/package/sass-loader
191
+ loader: require.resolve('sass-loader'),
192
+
193
+ options: {
194
+ implementation: sass,
195
+ sassOptions: {
196
+ includePaths: [path.resolve(__dirname, 'node_modules')]
197
+ },
198
+
199
+ sourceMap: !production
200
+ }
201
+ }
202
+ ]
203
+ }
204
+ ]
205
+ },
206
+
207
+ {
208
+ test: /\.(jpeg|jpg|png|gif|svg|ico)$/,
209
+ // Allows import/require() to be used with an asset file. The file will be copied to the output folder,
210
+ // and the import statement will return its URL.
211
+ // https://webpack.js.org/guides/asset-modules/#resource-assets
212
+ type: 'asset/resource'
213
+ }
214
+ ]
215
+ },
216
+ devServer: {
217
+ host: 'localhost',
218
+ port: 8080
219
+ },
220
+ // See here for documentation: https://webpack.js.org/configuration/devtool
221
+ devtool: production ? undefined : 'eval-source-map',
222
+ optimization: {
223
+ minimize: !!production,
224
+ nodeEnv: production ? 'production' : 'development',
225
+ minimizer: [
226
+ new CssMinimizerPlugin({
227
+ minimizerOptions: {
228
+ preset: ['default', { discardComments: { removeAll: !!production } }]
229
+ }
230
+ }),
231
+ // This magic constant indicates the minimizer defaults
232
+ // https://webpack.js.org/configuration/optimization/#optimizationminimizer
233
+ '...'
234
+ ]
235
+ },
236
+ plugins: [
237
+ // See here for documentation: https://webpack.js.org/plugins/mini-css-extract-plugin/
238
+ new MiniCssExtractPlugin({
239
+ filename: '[name].[contenthash].css'
240
+ }),
241
+
242
+ // See here for documentation: https://webpack.js.org/plugins/define-plugin/
243
+ new DefinePlugin({
244
+ DEBUG: !production
245
+ }),
246
+
247
+ process.env.REPORT ? new BundleAnalyzerPlugin({ analyzerMode: 'static' }) : undefined
248
+ ]
249
+ };
250
+
251
+ let result = mergeWithCustomize({
252
+ // Remove duplicate of HtmlWebpackPlugin
253
+ // this allows projects to override the default rig behavior if applicable (ex. when targeting older browsers)
254
+ customizeArray: unique(
255
+ 'plugins',
256
+ ['HtmlWebpackPlugin'],
257
+ (plugin) => plugin && plugin.constructor && plugin.constructor.name
258
+ )
259
+ })(defaultArgs, configOverride);
260
+
261
+ // Remove undefined/null plugins
262
+ if (Array.isArray(result.plugins)) {
263
+ result.plugins = result.plugins.filter(Boolean);
264
+ }
265
+
266
+ return result;
267
+ }
268
+
269
+ createWebpackConfig.merge = merge;
270
+ createWebpackConfig.mergeWithCustomize = mergeWithCustomize;
271
+ createWebpackConfig.mergeWithRules = mergeWithRules;
272
+
273
+ module.exports = createWebpackConfig;