-
Notifications
You must be signed in to change notification settings - Fork 13
/
ember-cli-build.js
137 lines (114 loc) · 4.47 KB
/
ember-cli-build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
require('dotenv').config();
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const config = require('./config/environment')(EmberApp.env());
const customFilePlugin = require('./lib/custom-file-plugin');
const fetch = require('node-fetch');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { Webpack } = require('@embroider/webpack');
const { codecovWebpackPlugin } = require('@codecov/webpack-plugin');
const { createEmberCLIConfig } = require('ember-cli-bundle-analyzer/create-config');
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
const shouldSpawnBundleAnalyzer = process.env.ANALYZE_BUNDLE === 'true';
const shouldUploadSentrySourcemaps = !!process.env.CI && !process.env.VERCEL;
module.exports = function (defaults) {
const appOptions = {
babel: {
plugins: [
require.resolve('ember-concurrency/async-arrow-task-transform'),
...require('ember-cli-code-coverage').buildBabelPlugin({ embroider: true }),
],
},
'@embroider/macros': {
setConfig: {
'@ember-data/store': {
polyfillUUID: true,
},
},
},
'ember-cli-babel': { enableTypeScriptTransform: true },
postcssOptions: {
compile: {
plugins: [
{
module: require('postcss-import'),
options: {
path: ['node_modules'],
},
},
],
},
},
sourcemaps: { enabled: true },
svgJar: {
sourceDirs: ['public/assets/images/heroicons/outline', 'public/assets/images/heroicons/solid', 'public/assets/images/svg-icons'],
},
prember: {
urls: async function generatePremberUrls() {
// Default routes to pre-generate with FastBoot
const urls = ['/', '/catalog'];
// Get a list of Courses and Languages from the API
const apiResponse = await fetch(`${config.x.backendUrl}/api/v1/courses?include=language-configurations.language`);
if (apiResponse.status !== 200) {
throw new Error(`Failed to load Courses and Languages from the API, status: ${apiResponse.status}`);
}
// Parse the response and make a combined list of all models
const payload = await apiResponse.json();
const models = [...(payload.data || []), ...(payload.included || [])];
// Add routes for all Courses
urls.push(...models.filter(({ type }) => type === 'courses').map(({ attributes: { slug } }) => `/courses/${slug}/overview`));
// Add routes for all Languages
urls.push(...models.filter(({ type }) => type === 'languages').map(({ attributes: { slug } }) => `/tracks/${slug}`));
urls.push('/collections/rust-primer'); // will update if we get more collections
// Return the full list of routes
return urls;
},
},
};
let app = new EmberApp(defaults, { ...appOptions, ...createEmberCLIConfig() });
const compiledApp = require('@embroider/compat').compatBuild(app, Webpack, {
staticAddonTestSupportTrees: true,
staticAddonTrees: true,
staticHelpers: true,
staticModifiers: true,
staticComponents: true,
splitAtRoutes: ['badges', 'concept', 'code-walkthrough', 'course', 'course-admin', 'concept-admin', 'demo'], // can also be a RegExp
packagerOptions: {
publicAssetURL: '/',
webpackConfig: {
plugins: [
customFilePlugin('version.txt', config.x.version),
codecovWebpackPlugin({
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
bundleName: 'client',
uploadToken: process.env.CODECOV_TOKEN,
}),
shouldUploadSentrySourcemaps
? sentryWebpackPlugin({
org: 'codecrafters',
project: 'frontend',
authToken: process.env.SENTRY_AUTH_TOKEN,
release: {
name: config.x.version,
},
})
: null,
shouldSpawnBundleAnalyzer ? new BundleAnalyzerPlugin() : null,
],
devtool: EmberApp.env() === 'development' ? 'eval-source-map' : 'source-map',
module: {
rules: [
{
test: /\.(glb|css|png|jpg|jpeg|gif|svg|ico|lottie\.json)$/,
type: 'asset/resource',
generator: {
filename: 'assets/[hash][ext][query]',
},
},
],
},
},
},
});
return require('prember').prerender(app, compiledApp);
};