Skip to content

Commit e62085a

Browse files
committed
We now ship a prod build out of the box (via package.json exports
conditions)
1 parent add9cd7 commit e62085a

5 files changed

Lines changed: 61 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ assets/bpm_libs.js
1717
assets/bpm_styles.css
1818
coverage
1919
dist
20+
dist-prod
2021
/docs
2122
lib/*/tests/all.js
2223
lib/*/tests/qunit*

broccoli/import-meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function importMetaRemoval(debugMacrosMode) {
1313
return;
1414
}
1515

16-
if (debugMacrosMode === false) {
16+
if (debugMacrosMode === false || debugMacrosMode === 'production') {
1717
if (hasDEV(code)) {
1818
return code.replace(/import.meta.env\??.DEV/g, 'false');
1919
}

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default [
2121
'docs/',
2222
'**/.*',
2323
'**/dist/',
24+
'**/dist-prod/',
2425
'**/tmp/',
2526
'**/smoke-tests/',
2627
'**/types/',

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
"ember-addon"
77
],
88
"exports": {
9-
"./*": "./dist/packages/*",
9+
"./*": {
10+
"development": "./dist/packages/*",
11+
"production": "./dist-prod/packages/*",
12+
"default": "./dist/packages/*"
13+
},
1014
"./types": {
1115
"types": "./types/stable/index.d.ts"
1216
},
@@ -24,6 +28,7 @@
2428
"blueprints",
2529
"dist/packages",
2630
"dist/dependencies",
31+
"dist-prod/packages",
2732
"dist/ember-template-compiler.js",
2833
"dist/ember-template-compiler.js.map",
2934
"dist/ember.debug.js",

rollup.config.mjs

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const testDependencies = [
2727

2828
let configs = [
2929
esmConfig(),
30-
esmTemplateCompiler(),
30+
esmProdConfig(),
3131
legacyBundleConfig('./broccoli/amd-compat-entrypoints/ember.debug.js', 'ember.debug.js', {
3232
isDeveloping: true,
3333
}),
@@ -55,61 +55,69 @@ export default configs;
5555

5656
function esmConfig() {
5757
return sharedESMConfig({
58-
input: {
59-
...renameEntrypoints(exposedDependencies(), (name) => join('packages', name, 'index')),
60-
...renameEntrypoints(packages(), (name) => join('packages', name)),
61-
},
58+
input: esmInputs(),
6259
debugMacrosMode: '@embroider/macros',
60+
includePackageMeta: true,
6361
});
6462
}
6563

66-
function esmTemplateCompiler() {
64+
function esmProdConfig() {
6765
return sharedESMConfig({
68-
input: {
69-
// the actual authored "./packages/ember-template-compiler/index.ts" is
70-
// part of what powers the historical dist/ember-template-compiler.js AMD
71-
// bundle. It has historical cruft that has never been present in our ESM
72-
// builds.
73-
//
74-
// On the ESM build, the main entrypoint of ember-template-compiler is the
75-
// "minimal.ts" version, which has a lot less in it.
76-
77-
'packages/ember-template-compiler/index': 'ember-template-compiler/minimal.ts',
78-
},
79-
// the template compiler is always in debug mode (and doesn't use
80-
// embroider/macros, so it's directly invokable on node)
81-
debugMacrosMode: true,
66+
input: esmInputs(),
67+
debugMacrosMode: 'production',
8268
});
8369
}
8470

85-
function sharedESMConfig({ input, debugMacrosMode }) {
71+
function esmInputs() {
72+
return {
73+
...renameEntrypoints(exposedDependencies(), (name) => join('packages', name, 'index')),
74+
...renameEntrypoints(packages(), (name) => join('packages', name)),
75+
// the actual authored "./packages/ember-template-compiler/index.ts" is
76+
// part of what powers the historical dist/ember-template-compiler.js AMD
77+
// bundle. It has historical cruft that has never been present in our ESM
78+
// builds.
79+
//
80+
// On the ESM build, the main entrypoint of ember-template-compiler is the
81+
// "minimal.ts" version, which has a lot less in it.
82+
83+
'packages/ember-template-compiler/index': 'ember-template-compiler/minimal.ts',
84+
};
85+
}
86+
87+
function sharedESMConfig({ input, debugMacrosMode, includePackageMeta = false }) {
88+
let outputDir = debugMacrosMode === 'production' ? 'dist-prod' : 'dist';
8689
let babelConfig = { ...sharedBabelConfig };
8790
babelConfig.plugins = [...babelConfig.plugins, canaryFeatures()];
8891

92+
let plugins = [
93+
importMetaRemoval(debugMacrosMode),
94+
babel({
95+
babelHelpers: 'bundled',
96+
extensions: ['.js', '.ts'],
97+
configFile: false,
98+
...babelConfig,
99+
}),
100+
resolveTS(),
101+
version(),
102+
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }),
103+
pruneEmptyBundles(),
104+
];
105+
106+
if (includePackageMeta) {
107+
plugins.push(packageMeta());
108+
}
109+
89110
return {
90111
onLog: handleRollupWarnings,
91112
input,
92113
output: {
93114
format: 'es',
94-
dir: 'dist',
115+
dir: outputDir,
95116
hoistTransitiveImports: false,
96117
generatedCode: 'es2015',
97118
chunkFileNames: 'packages/shared-chunks/[name]-[hash].js',
98119
},
99-
plugins: [
100-
importMetaRemoval(debugMacrosMode),
101-
babel({
102-
babelHelpers: 'bundled',
103-
extensions: ['.js', '.ts'],
104-
configFile: false,
105-
...babelConfig,
106-
}),
107-
resolveTS(),
108-
version(),
109-
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }),
110-
pruneEmptyBundles(),
111-
packageMeta(),
112-
],
120+
plugins,
113121
};
114122
}
115123

@@ -642,11 +650,15 @@ function pruneEmptyBundles() {
642650
function packageMeta() {
643651
return {
644652
name: 'package-meta',
645-
generateBundle() {
653+
generateBundle(_outputOptions, bundle) {
646654
let renamedModules = Object.fromEntries(
647-
glob
648-
.sync('packages/**/*.js', { cwd: 'dist', nodir: true })
649-
.filter((name) => !name.startsWith('packages/shared-chunks/'))
655+
Object.keys(bundle)
656+
.filter(
657+
(name) =>
658+
name.startsWith('packages/') &&
659+
!name.startsWith('packages/shared-chunks/') &&
660+
name.endsWith('.js')
661+
)
650662
.sort()
651663
.map((name) => {
652664
return [

0 commit comments

Comments
 (0)