Skip to content

Commit

Permalink
fix(compiler): generate loader when es5 is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Jun 20, 2019
1 parent 0bbda39 commit 0b4d814
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 29 deletions.
3 changes: 0 additions & 3 deletions src/compiler/component-lazy/generate-cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { OutputOptions, RollupBuild } from 'rollup';
import { relativeImport } from '@utils';

export async function generateCjs(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, _build: d.Build, rollupBuild: RollupBuild, outputTargets: d.OutputTargetDistLazy[]) {
if (!config.buildDist) {
return;
}
const cjsOutputs = outputTargets.filter(o => !!o.cjsDir);

if (cjsOutputs.length > 0) {
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/component-lazy/generate-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { relativeImport } from '@utils';
import { RollupResult } from '../../declarations';

export async function generateEsm(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, rollupBuild: RollupBuild, outputTargets: d.OutputTargetDistLazy[]) {
if (!config.buildDist) {
return;
}

const esmEs5Outputs = config.buildEs5 ? outputTargets.filter(o => !!o.esmEs5Dir && !o.isBrowserBuild) : [];
const esmOutputs = outputTargets.filter(o => !!o.esmDir && !o.isBrowserBuild);
if (esmOutputs.length + esmEs5Outputs.length > 0) {
Expand Down
3 changes: 0 additions & 3 deletions src/compiler/component-lazy/generate-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { OutputOptions, RollupBuild } from 'rollup';
import { relativeImport } from '@utils';

export async function generateSystem(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, build: d.Build, rollupBuild: RollupBuild, outputTargets: d.OutputTargetDistLazy[]) {
if (!config.buildEs5) {
return;
}
const systemOutputs = outputTargets.filter(o => !!o.systemDir);

if (systemOutputs.length > 0) {
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/config/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export function validateConfig(config: d.Config, diagnostics: d.Diagnostic[], se
setBooleanConfig(config, 'minifyJs', null, !config.devMode);

setBooleanConfig(config, 'buildEs5', 'es5', !config.devMode);
setBooleanConfig(config, 'buildDist', 'esm', config.buildEs5);
setBooleanConfig(config, 'buildScoped', null, config.buildEs5);
setBooleanConfig(config, 'buildDist', 'esm', !config.devMode || config.buildEs5);

// setup the outputTargets
validateOutputTargets(config, diagnostics);
Expand All @@ -100,7 +99,6 @@ export function validateConfig(config: d.Config, diagnostics: d.Diagnostic[], se
}
}


validateDevServer(config, diagnostics);

if (!config.watchIgnoredRegex) {
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/config/validate-outputs-dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ export function validateOutputTargetDist(config: d.Config) {

const namespace = config.fsNamespace || 'app';
const lazyDir = path.join(outputTarget.buildDir, namespace);

// Lazy build for CDN in dist
config.outputTargets.push({
type: DIST_LAZY,
copyDir: lazyDir,
esmDir: lazyDir,
systemDir: lazyDir,
systemLoaderFile: path.join(lazyDir, namespace + '.js'),
systemDir: config.buildEs5 ? lazyDir : undefined,
systemLoaderFile: config.buildEs5 ? path.join(lazyDir, namespace + '.js') : undefined,
legacyLoaderFile: path.join(outputTarget.buildDir, namespace + '.js'),
polyfills: true,
isBrowserBuild: true,
Expand All @@ -101,7 +102,7 @@ export function validateOutputTargetDist(config: d.Config) {

if (config.buildDist) {
const esmDir = path.join(outputTarget.dir, 'esm');
const esmEs5Dir = path.join(outputTarget.dir, 'esm', 'legacy');
const esmEs5Dir = config.buildEs5 ? path.join(outputTarget.dir, 'esm', 'legacy') : undefined;
const cjsDir = path.join(outputTarget.dir, 'cjs');

// Create lazy output-target
Expand Down
26 changes: 13 additions & 13 deletions src/compiler/output-targets/output-lazy-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { normalizePath, relativeImport } from '@utils';
import { getClientPolyfill } from '../app-core/app-polyfills';

export async function outputLazyLoader(config: d.Config, compilerCtx: d.CompilerCtx) {
if (!config.buildDist) {
return;
}

const outputTargets = config.outputTargets.filter(isOutputTargetDistLazyLoader);
if (outputTargets.length === 0) {
return;
Expand Down Expand Up @@ -44,17 +40,21 @@ async function generateLoader(config: d.Config, compilerCtx: d.CompilerCtx, outp
const es5EntryPoint = config.sys.path.join(es5Dir, 'loader.mjs');
const es2017EntryPoint = config.sys.path.join(es2017Dir, 'loader.mjs');
const polyfillsEntryPoint = config.sys.path.join(es2017Dir, 'polyfills/index.js');

const cjsEntryPoint = config.sys.path.join(cjsDir, 'loader.cjs.js');

const polyfillsExport = `export * from '${normalizePath(config.sys.path.relative(loaderPath, polyfillsEntryPoint))}';\n`;
const indexPath = config.buildEs5 ? es5EntryPoint : es2017EntryPoint;
const indexContent = `${es5HtmlElement}\n${polyfillsExport}export * from '${normalizePath(config.sys.path.relative(loaderPath, indexPath))}';`;
const indexES2017Content = `${polyfillsExport}export * from '${normalizePath(config.sys.path.relative(loaderPath, es2017EntryPoint))}';`;
const polyfillsExport = `export * from '${normalizePath(config.sys.path.relative(loaderPath, polyfillsEntryPoint))}';`;
const indexContent = `
${es5HtmlElement}
${polyfillsExport}
export * from '${normalizePath(config.sys.path.relative(loaderPath, es5EntryPoint))}';
`;
const indexES2017Content = `
${polyfillsExport}
export * from '${normalizePath(config.sys.path.relative(loaderPath, es2017EntryPoint))}';
`;
const indexCjsContent = `
module.exports = require('${normalizePath(config.sys.path.relative(loaderPath, cjsEntryPoint))}');
module.exports.applyPolyfills = function() { return Promise.resolve() };
`;
module.exports = require('${normalizePath(config.sys.path.relative(loaderPath, cjsEntryPoint))}');
module.exports.applyPolyfills = function() { return Promise.resolve() };
`;

const indexDtsPath = config.sys.path.join(loaderPath, 'index.d.ts');
await Promise.all([
Expand Down

0 comments on commit 0b4d814

Please sign in to comment.