diff --git a/src/api/build.ts b/src/api/build.ts index 941c126..572685a 100644 --- a/src/api/build.ts +++ b/src/api/build.ts @@ -55,7 +55,7 @@ async function execute(emitter: EventEmitter, { const route_objects = create_routes(); // create app/manifest/client.js and app/manifest/server.js - create_main_manifests({ routes: route_objects }); + create_main_manifests({ bundler, routes: route_objects }); const { client, server, serviceworker } = create_compilers(validate_bundler(bundler), { webpack, rollup }); diff --git a/src/api/dev.ts b/src/api/dev.ts index 301a5e7..b15c377 100644 --- a/src/api/dev.ts +++ b/src/api/dev.ts @@ -124,7 +124,7 @@ class Watcher extends EventEmitter { try { const routes = create_routes(); - create_main_manifests({ routes, dev_port }); + create_main_manifests({ bundler: this.bundler, routes, dev_port }); } catch (err) { this.emit('fatal', { message: err.message @@ -145,11 +145,11 @@ class Watcher extends EventEmitter { }, () => { const routes = create_routes(); - create_main_manifests({ routes, dev_port }); + create_main_manifests({ bundler: this.bundler, routes, dev_port }); try { const routes = create_routes(); - create_main_manifests({ routes, dev_port }); + create_main_manifests({ bundler: this.bundler, routes, dev_port }); } catch (err) { this.emit('error', { message: err.message diff --git a/src/core/create_manifests.ts b/src/core/create_manifests.ts index 8152312..518f692 100644 --- a/src/core/create_manifests.ts +++ b/src/core/create_manifests.ts @@ -5,7 +5,8 @@ import { posixify, write_if_changed } from './utils'; import { dev, locations } from '../config'; import { Page, PageComponent, ServerRoute } from '../interfaces'; -export function create_main_manifests({ routes, dev_port }: { +export function create_main_manifests({ bundler, routes, dev_port }: { + bundler: string, routes: { components: PageComponent[], pages: Page[], server_routes: ServerRoute[] }; dev_port?: number; }) { @@ -14,7 +15,7 @@ export function create_main_manifests({ routes, dev_port }: { const path_to_routes = path.relative(manifest_dir, locations.routes()); - const client_manifest = generate_client(routes, path_to_routes, dev_port); + const client_manifest = generate_client(routes, path_to_routes, bundler, dev_port); const server_manifest = generate_server(routes, path_to_routes); write_if_changed( @@ -48,6 +49,7 @@ export function create_serviceworker_manifest({ routes, client_files }: { function generate_client( routes: { root: PageComponent, components: PageComponent[], pages: Page[], server_routes: ServerRoute[] }, path_to_routes: string, + bundler: string, dev_port?: number ) { const page_ids = new Set(routes.pages.map(page => @@ -61,10 +63,15 @@ function generate_client( import root from '${get_file(path_to_routes, routes.root)}'; import error from '${posixify(`${path_to_routes}/_error.html`)}'; - ${routes.components.map(component => - `const ${component.name} = () => - import(/* webpackChunkName: "${component.name}" */ '${get_file(path_to_routes, component)}');`) - .join('\n')} + ${routes.components.map(component => { + const annotation = bundler === 'webpack' + ? `/* webpackChunkName: "${component.name}" */ ` + : ''; + + const source = get_file(path_to_routes, component); + + return `const ${component.name} = () => import(${annotation}'${source}');`; + }).join('\n')} export const manifest = { ignore: [${server_routes_to_ignore.map(route => route.pattern).join(', ')}],