what-compiler 0.10.0 → 0.11.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.
- package/dist/babel-plugin.js +243 -57
- package/dist/babel-plugin.js.map +2 -2
- package/dist/babel-plugin.min.js +1 -1
- package/dist/babel-plugin.min.js.map +3 -3
- package/dist/index.js +259 -59
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +6 -6
- package/dist/index.min.js.map +3 -3
- package/dist/vite-plugin.js +259 -59
- package/dist/vite-plugin.js.map +2 -2
- package/dist/vite-plugin.min.js +6 -6
- package/dist/vite-plugin.min.js.map +3 -3
- package/package.json +2 -2
- package/src/babel-plugin.js +433 -89
- package/src/vite-plugin.js +32 -1
package/src/vite-plugin.js
CHANGED
|
@@ -36,6 +36,11 @@ export default function whatVitePlugin(options = {}) {
|
|
|
36
36
|
pages = 'src/pages',
|
|
37
37
|
// HMR: enabled by default in dev, disabled in production
|
|
38
38
|
hot = !production,
|
|
39
|
+
// Resolve the `production` exports condition (dist/*.min.js — pre-minified,
|
|
40
|
+
// dev warnings compiled out) during `vite build`. Set to false to build
|
|
41
|
+
// against package sources instead — needed e.g. in a monorepo where
|
|
42
|
+
// workspace-linked dist/ output may be stale or absent. See config() below.
|
|
43
|
+
prodBundles = true,
|
|
39
44
|
} = options;
|
|
40
45
|
|
|
41
46
|
let rootDir = '';
|
|
@@ -105,6 +110,13 @@ export default function whatVitePlugin(options = {}) {
|
|
|
105
110
|
const result = transformSync(code, {
|
|
106
111
|
filename: id,
|
|
107
112
|
sourceMaps,
|
|
113
|
+
// Hermetic transform (SPRINT v0.11 C7): never load the project's
|
|
114
|
+
// babel.config.js/.babelrc. A user's React preset or unrelated
|
|
115
|
+
// plugins corrupting What's JSX output is a debugging nightmare —
|
|
116
|
+
// and scanning the disk for config files on every transform is
|
|
117
|
+
// wasted I/O in dev.
|
|
118
|
+
configFile: false,
|
|
119
|
+
babelrc: false,
|
|
108
120
|
plugins: [
|
|
109
121
|
[whatBabelPlugin, { production }]
|
|
110
122
|
],
|
|
@@ -165,8 +177,27 @@ export default function whatVitePlugin(options = {}) {
|
|
|
165
177
|
},
|
|
166
178
|
|
|
167
179
|
// Configure for development
|
|
168
|
-
config(config, { mode }) {
|
|
180
|
+
config(config, { mode, command }) {
|
|
181
|
+
// SPRINT v0.11 C7: make the `production` exports condition reachable.
|
|
182
|
+
// what-framework/what-core ship pre-minified production bundles behind
|
|
183
|
+
// the `production` condition in their exports maps, but Vite's default
|
|
184
|
+
// resolve conditions never include `production` — so production builds
|
|
185
|
+
// silently shipped the dev source (larger, with dev-only warnings).
|
|
186
|
+
//
|
|
187
|
+
// Guard rationale (documented choice):
|
|
188
|
+
// - Only during `vite build` in production mode — dev always uses src
|
|
189
|
+
// so the dev server, HMR, and devtools see un-minified modules.
|
|
190
|
+
// - Opt-out via `what({ prodBundles: false })` — in a monorepo with
|
|
191
|
+
// workspace-linked packages, dist/ can be stale (or missing before
|
|
192
|
+
// the first `npm run build`), and resolving `production` there would
|
|
193
|
+
// bundle outdated framework code. Apps installing from npm always
|
|
194
|
+
// have dist/ in sync with the published package, so the default is on.
|
|
195
|
+
// - `resolve.conditions` is ADDITIVE in Vite (extra conditions on top
|
|
196
|
+
// of the defaults), so import/browser/default resolution for other
|
|
197
|
+
// packages is unaffected.
|
|
198
|
+
const useProdCondition = command === 'build' && mode === 'production' && prodBundles;
|
|
169
199
|
return {
|
|
200
|
+
...(useProdCondition ? { resolve: { conditions: ['production'] } } : {}),
|
|
170
201
|
esbuild: {
|
|
171
202
|
// Preserve JSX so our babel plugin handles it -- don't let esbuild transform it
|
|
172
203
|
jsx: 'preserve',
|