@corespeed/webpack 0.0.0 → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +689 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.mjs +675 -0
- package/package.json +84 -8
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Configuration, ExternalItemObjectKnown, ExternalItemObjectUnknown } from 'webpack';
|
|
2
|
+
import { DotenvConfigOptions } from 'dotenv';
|
|
3
|
+
import { GetPortOptions } from 'get-port-please';
|
|
4
|
+
import { ReactCompilerLoaderOption } from 'react-compiler-webpack';
|
|
5
|
+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
|
|
6
|
+
|
|
7
|
+
type WebpackConfigurationOutput = NonNullable<Configuration['output']>;
|
|
8
|
+
interface CreateWebpackOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Current working directory, used to resolve relative paths.
|
|
11
|
+
*
|
|
12
|
+
* There is no default value, you must provide this option.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* // either
|
|
17
|
+
* cwd: __dirname
|
|
18
|
+
* // or
|
|
19
|
+
* cwd: import.meta.dirname
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
cwd: string;
|
|
23
|
+
/**
|
|
24
|
+
* @default process.env.NODE_ENV === 'development'
|
|
25
|
+
*/
|
|
26
|
+
development?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Enable Single Page Application (SPA) mode.
|
|
29
|
+
*
|
|
30
|
+
* When enabled, this will enables `devServer.historyApiFallback` option.
|
|
31
|
+
*
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
spa?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Directory to serve static files from.
|
|
37
|
+
*
|
|
38
|
+
* During development, this will be used as `devServer.static.directory` option.
|
|
39
|
+
* During production build, the CopyWebpackPlugin will be used to copy files from this directory to `output.path`.
|
|
40
|
+
*
|
|
41
|
+
* @default undefined
|
|
42
|
+
*/
|
|
43
|
+
publicDir?: string;
|
|
44
|
+
entry?: Configuration['entry'];
|
|
45
|
+
/**
|
|
46
|
+
* Path to HTML template file.
|
|
47
|
+
*
|
|
48
|
+
* This will be used by `html-webpack-plugin` to generate the final `index.html`.
|
|
49
|
+
*
|
|
50
|
+
* If not specificied, the `html-webpack-plugin` will not be enabled
|
|
51
|
+
*/
|
|
52
|
+
htmlTemplatePath?: string;
|
|
53
|
+
output?: {
|
|
54
|
+
/**
|
|
55
|
+
* `output.path`
|
|
56
|
+
*
|
|
57
|
+
* @default undefined
|
|
58
|
+
*/
|
|
59
|
+
path?: WebpackConfigurationOutput['path'];
|
|
60
|
+
/**
|
|
61
|
+
* `output.library`
|
|
62
|
+
*
|
|
63
|
+
* @default undefined
|
|
64
|
+
*/
|
|
65
|
+
library?: WebpackConfigurationOutput['library'];
|
|
66
|
+
/**
|
|
67
|
+
* Show chunk name in filename.
|
|
68
|
+
* When enabled, `output` filename format will contain `[name]`, making it easier to identify chunks during debugging.
|
|
69
|
+
* Disable to reduce filename length and hide implementation details.
|
|
70
|
+
*
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
filenameContainChunkName?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Controls filename prefix for output files, this will append to `output.filename`, `output.chunkFilename`, etc.
|
|
76
|
+
* This allows for easy CDN cache policy management / WAF Rules (via path prefix).
|
|
77
|
+
*
|
|
78
|
+
* @default '/_assets/static/'
|
|
79
|
+
*/
|
|
80
|
+
filenamePrefix?: string;
|
|
81
|
+
/**
|
|
82
|
+
* `output.crossOriginLoading` setting.
|
|
83
|
+
*
|
|
84
|
+
* @default undefined
|
|
85
|
+
*/
|
|
86
|
+
crossOriginLoading?: WebpackConfigurationOutput['crossOriginLoading'];
|
|
87
|
+
};
|
|
88
|
+
sourcemap?: {
|
|
89
|
+
/**
|
|
90
|
+
* `devtool` configuration used for development mode.
|
|
91
|
+
*
|
|
92
|
+
* @default 'eval-source-map'
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* 'eval-cheap-module-source-map' // faster development w/ large scale codebase, with trade-off on source map quality.
|
|
96
|
+
*/
|
|
97
|
+
development?: Configuration['devtool'];
|
|
98
|
+
/**
|
|
99
|
+
* `devtool` configuration used for development mode.
|
|
100
|
+
*
|
|
101
|
+
* @default 'hidden-source-map' // this works with error reporting services like Sentry.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* false // completely disable source map in production. this will break w/ error reporting services like Sentry.
|
|
105
|
+
*/
|
|
106
|
+
production?: Configuration['devtool'];
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Dev Server port. Uses `get-port-please` library under the hood to gracefully find available port.
|
|
110
|
+
*/
|
|
111
|
+
devServerPort?: {
|
|
112
|
+
/** `process.env.PORT` will always be preferred over this value.
|
|
113
|
+
*
|
|
114
|
+
* @default 3000
|
|
115
|
+
*/
|
|
116
|
+
fallbackPort?: number;
|
|
117
|
+
/** Additional ports to try (in addition to the default port and fallbackPort). */
|
|
118
|
+
ports?: GetPortOptions['ports'];
|
|
119
|
+
/**
|
|
120
|
+
* Port range to try.
|
|
121
|
+
* */
|
|
122
|
+
portRange?: GetPortOptions['portRange'];
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Webpack externals options, but only accepts object format
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
*
|
|
129
|
+
* ```js
|
|
130
|
+
* externals: {
|
|
131
|
+
* // remove polyfills
|
|
132
|
+
* 'text-encoding': 'TextEncoder',
|
|
133
|
+
* 'whatwg-url': 'window',
|
|
134
|
+
* '@trust/webcrypto': 'crypto',
|
|
135
|
+
* 'isomorphic-fetch': 'fetch',
|
|
136
|
+
* 'node-fetch': 'fetch',
|
|
137
|
+
* // allow jQuery and Lodash to be loaded from CDN
|
|
138
|
+
* jquery: 'jQuery',
|
|
139
|
+
* lodash: '_',
|
|
140
|
+
* // required to bundle "@undecaf/zbar.wasm"
|
|
141
|
+
* module: 'module',
|
|
142
|
+
* // bundle shopify frone-end application
|
|
143
|
+
* 'shopify-buy': 'ShopifyBuy'
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
externals?: ExternalItemObjectKnown & ExternalItemObjectUnknown;
|
|
148
|
+
/**
|
|
149
|
+
* This is an array of top-level framework package names, they will be bundled together into a single "framework" chunk.
|
|
150
|
+
* The idea is that these framework packages are less likely to change frequently, so by bundling them together it can
|
|
151
|
+
* maxmize caching efficiency for both CDN and browser.
|
|
152
|
+
*
|
|
153
|
+
* @default ['react', 'react-dom', 'wouter', 'react-router', 'react-router-dom']
|
|
154
|
+
*/
|
|
155
|
+
topLevelFrameworkPackages?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* Enable experimental built-in CSS support (will be stablized in Webpack 6).
|
|
158
|
+
* When disabled (default), CSS support will be handled via `mini-css-extract-plugin` and `css-loader`.
|
|
159
|
+
*
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
webpackExperimentalBuiltinCssSupport?: boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Enable `postcss-loader`. This allows you to run PostCSS plugins like Tailwind CSS.
|
|
165
|
+
*
|
|
166
|
+
* You need to manually install `postcss-loader` in your project for this to work.
|
|
167
|
+
*
|
|
168
|
+
* @default false
|
|
169
|
+
*/
|
|
170
|
+
postcss?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Enable `@svgr/webpack` loader for SVG files.
|
|
173
|
+
*
|
|
174
|
+
* You need to manually install `@svgr/webpack` in your project for this to work.
|
|
175
|
+
*
|
|
176
|
+
* @default false
|
|
177
|
+
*/
|
|
178
|
+
svgr?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Enable React Compiler loader via `react-compiler-webpack`.
|
|
181
|
+
*
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
reactCompiler?: boolean | ReactCompilerLoaderOption;
|
|
185
|
+
/**
|
|
186
|
+
* Enable bundle analysis using `webpack-bundle-analyzer`.
|
|
187
|
+
*
|
|
188
|
+
* @default process.env.ANALYZE === 'true'
|
|
189
|
+
*/
|
|
190
|
+
analyze?: boolean | BundleAnalyzerPlugin.Options;
|
|
191
|
+
/**
|
|
192
|
+
* Other webpack plugins to use.
|
|
193
|
+
*/
|
|
194
|
+
plugins?: Configuration['plugins'];
|
|
195
|
+
dotenv?: boolean | DotenvConfigOptions;
|
|
196
|
+
/**
|
|
197
|
+
* By default we will use "browserlists" package to looking for config, like `.browserslistrc` file or `browserslist` field in `package.json`, etc.
|
|
198
|
+
*
|
|
199
|
+
* But if you wish, you can also directly specify the browserlists here.
|
|
200
|
+
*/
|
|
201
|
+
browserlists?: string | string[];
|
|
202
|
+
/**
|
|
203
|
+
* Enable alias lodash to lodash-es for better tree-shaking.
|
|
204
|
+
*
|
|
205
|
+
* @default false
|
|
206
|
+
*/
|
|
207
|
+
lodashTreeShaking?: boolean;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Usage:
|
|
212
|
+
*
|
|
213
|
+
* ```js
|
|
214
|
+
* // webpack.config.js
|
|
215
|
+
* const { createWebpck } = require('@corespeed/webpack');
|
|
216
|
+
* const path = require('node:path');
|
|
217
|
+
*
|
|
218
|
+
* module.exports = createWebpack({
|
|
219
|
+
* // your options here
|
|
220
|
+
* }, {
|
|
221
|
+
* // your custom webpack config here
|
|
222
|
+
* });
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare function createWebpack(options: CreateWebpackOptions, customWebpackOptions?: Configuration): Promise<Configuration>;
|
|
226
|
+
|
|
227
|
+
export { createWebpack };
|
|
228
|
+
export type { CreateWebpackOptions };
|