Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to support Node during Build Time Render #221

Merged
merged 4 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ function loadRoutingOutlets() {
const routesConfig = path.join(basePath, 'src', 'routes.ts');
try {
if (existsSync(routesConfig)) {
tsnode.register();
const routes: any[] = require(slash(routesConfig)).default;
return routes.map((route) => route.outlet);
}
Expand All @@ -151,6 +150,7 @@ function loadRoutingOutlets() {
}

export default function webpackConfigFactory(args: any): webpack.Configuration {
tsnode.register();
const extensions = args.legacy ? ['.ts', '.tsx', '.js'] : ['.ts', '.tsx', '.mjs', '.js'];
const compilerOptions = args.legacy ? {} : { target: 'es6', module: 'esnext' };
let features = args.legacy ? args.features : { ...(args.features || {}), ...getFeatures('modern') };
Expand Down
4 changes: 2 additions & 2 deletions src/dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as ManifestPlugin from 'webpack-manifest-plugin';
const WebpackPwaManifest = require('webpack-pwa-manifest');

function webpackConfig(args: any): webpack.Configuration {
const basePath = process.cwd();
const config = baseConfigFactory(args);
const manifest: WebAppManifest = args.pwa && args.pwa.manifest;
const serviceWorker: string | ServiceWorkerOptions = args.pwa && args.pwa.serviceWorker;
Expand Down Expand Up @@ -86,7 +87,7 @@ function webpackConfig(args: any): webpack.Configuration {
new BuildTimeRender({
...args['build-time-render'],
entries: Object.keys(config.entry!),
useManifest: true
basePath
})
);
}
Expand All @@ -96,7 +97,6 @@ function webpackConfig(args: any): webpack.Configuration {
path: outputPath
};

config.devtool = 'inline-source-map';
return config;
}

Expand Down
3 changes: 2 additions & 1 deletion src/dist.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All rights reserved
`;

function webpackConfig(args: any): webpack.Configuration {
const basePath = process.cwd();
const config = baseConfigFactory(args);
const manifest: WebAppManifest = args.pwa && args.pwa.manifest;
const serviceWorker: ServiceWorkerOptions = args.pwa && args.pwa.serviceWorker;
Expand Down Expand Up @@ -99,7 +100,7 @@ function webpackConfig(args: any): webpack.Configuration {
new BuildTimeRender({
...args['build-time-render'],
entries: Object.keys(config.entry!),
useManifest: true
basePath
})
);
}
Expand Down
38 changes: 19 additions & 19 deletions test-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test-app/src/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello from a text file
15 changes: 14 additions & 1 deletion test-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './Bar';
import LazyApp from './LazyApp';
import routes from './routes';
import myTheme from './themes/test-app/theme';
import test from './test.build';

console.log(myTheme);

Expand All @@ -18,6 +19,8 @@ if (has('foo')) {
console.log('foo');
}

const root = document.getElementById('app');

const btr = has('build-time-render');

App().then((result) => {
Expand All @@ -30,7 +33,18 @@ if (!div) {
div.id = 'div';
}
if (btr) {
test('./src/foo.txt').then((result: string) => {
const nodeBtr = document.createElement('div');
nodeBtr.id = 'nodeBtr';
nodeBtr.innerHTML = result;
root!.appendChild(nodeBtr);
});
div.setAttribute('hasBtr', 'true');
} else {
const nodeBtrCache = document.createElement('div');
nodeBtrCache.id = 'nodeBtrCache';
nodeBtrCache.innerHTML = test('./src/foo.txt');
root!.appendChild(nodeBtrCache);
}

if (process.env.NODE_ENV === 'production') {
Expand All @@ -53,7 +67,6 @@ div.textContent = `Built with Build Time Render: ${!!div.getAttribute('hasBtr')}
Currently Rendered by BTR: ${has('build-time-render')}`;

div.classList.add(...css.root.split(' '));
const root = document.getElementById('app');
if (div.parentNode === null) {
root!.appendChild(div);
}
Expand Down
5 changes: 5 additions & 0 deletions test-app/src/test.build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const fs = require('fs');

export default function(path: string) {
return fs.readFileSync(path, 'utf-8');
}
3 changes: 3 additions & 0 deletions tests/integration/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Currently Rendered by BTR: false`
cy.get('meta[name="apple-mobile-web-app-title"]').should(isPwa ? 'exist' : 'not.exist');
cy.get('meta[name="apple-mobile-web-app-status-bar-style"]').should(isPwa ? 'exist' : 'not.exist');
cy.get('link[rel="apple-touch-icon"]').should('have.length', isPwa ? 2 : 0);

cy.get('#nodeBtr').should('contain', 'hello from a text file');
cy.get('#nodeBtrCache').should('contain', 'hello from a text file');
}

it('dist', () => {
Expand Down