Skip to content

Commit

Permalink
feat(buildEs5): add "prod" as an option for config.buildEs5
Browse files Browse the repository at this point in the history
In Stencil v2, the default is to not build es5 in production, whereas v1 did. Setting buildEs5 to "prod" will only build es5 in production mode, which is the same as to how v1 worked by default.
  • Loading branch information
adamdbradley committed Aug 14, 2020
1 parent 1b1ad62 commit 1af30a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
21 changes: 21 additions & 0 deletions src/compiler/config/test/validate-config.spec.ts
Expand Up @@ -86,13 +86,34 @@ describe('validation', () => {
expect(config.buildEs5).toBe(true);
});

it('set buildEs5 true, dev mode', () => {
userConfig.devMode = true;
userConfig.buildEs5 = true;
const { config } = validateConfig(userConfig);
expect(config.buildEs5).toBe(true);
});

it('prod mode, set modern and es5', () => {
userConfig.devMode = false;
userConfig.buildEs5 = true;
const { config } = validateConfig(userConfig);
expect(config.buildEs5).toBe(true);
});

it('build es5 when set to "prod" and in prod', () => {
userConfig.devMode = false;
userConfig.buildEs5 = 'prod';
const { config } = validateConfig(userConfig);
expect(config.buildEs5).toBe(true);
});

it('do not build es5 when set to "prod" and in dev', () => {
userConfig.devMode = true;
userConfig.buildEs5 = 'prod';
const { config } = validateConfig(userConfig);
expect(config.buildEs5).toBe(false);
});

it('prod mode default to only modern and not es5', () => {
userConfig.devMode = false;
const { config } = validateConfig(userConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/config/validate-config.ts
Expand Up @@ -41,7 +41,7 @@ export const validateConfig = (userConfig?: Config) => {
config.extras.initializeNextTick = !!config.extras.initializeNextTick;
config.extras.tagNameTransform = !!config.extras.tagNameTransform;

config.buildEs5 = !!config.buildEs5;
config.buildEs5 = config.buildEs5 === true || (!config.devMode && config.buildEs5 === 'prod');

setBooleanConfig(config, 'minifyCss', null, !config.devMode);
setBooleanConfig(config, 'minifyJs', null, !config.devMode);
Expand Down
17 changes: 7 additions & 10 deletions src/declarations/stencil-public-compiler.ts
Expand Up @@ -115,16 +115,13 @@ export interface StencilConfig {
rollupConfig?: RollupConfig;

/**
* Sets if the ES5 build should be generated or not. It defaults to `false` in dev mode, and `true` in
* production mode. Notice that Stencil always generates a modern build too, whereas this setting
* will either disable es5 builds entirely with `false`, or always create es5 builds (even in dev mode)
* when set to `true`. Basically if the app does not need to run on legacy browsers
* (IE11 and Edge 18 and below), it's safe to set `buildEs5` to `false`, which will also speed up
* production build times. In addition to not creating es5 builds, apps may also be interested in
* disabling any unnecessary runtime when support legacy browsers. See
* [https://stenciljs.com/docs/config-extras](/docs/config-extras) for more information.
*/
buildEs5?: boolean;
* Sets if the ES5 build should be generated or not. Stencil generates a modern build without ES5,
* whereas this setting to `true` will also create es5 builds for both dev and prod modes. Setting
* `buildEs5` to `prod` will only build ES5 in prod mode. Basically if the app does not need to run
* on legacy browsers (IE11 and Edge 18 and below), it's safe to not build ES5, which will also speed
* up build times. Defaults to `false`.
*/
buildEs5?: boolean | 'prod';

/**
* Sets if the JS browser files are minified or not. Stencil uses `terser` under the hood.
Expand Down

0 comments on commit 1af30a2

Please sign in to comment.