From 4b35b8fee011f22850c4b11f799b2029ab31e67c Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sun, 28 Mar 2021 22:16:18 +0200 Subject: [PATCH] Add support for using .htm instead of .html files --- .changeset/gorgeous-badgers-bake.md | 6 ++++++ packages/nomodule-plugin/index.js | 2 +- packages/wmr/src/lib/output-utils.js | 2 +- .../wmr/src/plugins/html-entries-plugin.js | 6 +++--- .../wmr/src/plugins/optimize-graph-plugin.js | 2 +- packages/wmr/src/plugins/wmr/client.js | 2 +- packages/wmr/test/fixtures.test.js | 7 +++++++ .../wmr/test/fixtures/htm-index/public/foo.js | 1 + .../test/fixtures/htm-index/public/index.htm | 7 +++++++ .../test/fixtures/htm-index/public/index.js | 3 +++ .../test/fixtures/prod-htm-index/public/foo.js | 1 + .../fixtures/prod-htm-index/public/index.htm | 7 +++++++ .../fixtures/prod-htm-index/public/index.js | 3 +++ packages/wmr/test/production.test.js | 18 ++++++++++++++++++ 14 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 .changeset/gorgeous-badgers-bake.md create mode 100644 packages/wmr/test/fixtures/htm-index/public/foo.js create mode 100644 packages/wmr/test/fixtures/htm-index/public/index.htm create mode 100644 packages/wmr/test/fixtures/htm-index/public/index.js create mode 100644 packages/wmr/test/fixtures/prod-htm-index/public/foo.js create mode 100644 packages/wmr/test/fixtures/prod-htm-index/public/index.htm create mode 100644 packages/wmr/test/fixtures/prod-htm-index/public/index.js diff --git a/.changeset/gorgeous-badgers-bake.md b/.changeset/gorgeous-badgers-bake.md new file mode 100644 index 000000000..61f95a75b --- /dev/null +++ b/.changeset/gorgeous-badgers-bake.md @@ -0,0 +1,6 @@ +--- +'@wmr-plugins/nomodule': minor +'wmr': minor +--- + +Add support for .htm extension for HTML files diff --git a/packages/nomodule-plugin/index.js b/packages/nomodule-plugin/index.js index df04883e0..7f9b99da1 100644 --- a/packages/nomodule-plugin/index.js +++ b/packages/nomodule-plugin/index.js @@ -32,7 +32,7 @@ function nomodulePlugin({} = {}) { // Update all the HTML files with + + diff --git a/packages/wmr/test/fixtures/htm-index/public/index.js b/packages/wmr/test/fixtures/htm-index/public/index.js new file mode 100644 index 000000000..eaf8f3ac3 --- /dev/null +++ b/packages/wmr/test/fixtures/htm-index/public/index.js @@ -0,0 +1,3 @@ +import { foo } from './foo.js'; + +document.querySelector('h1').textContent = foo; diff --git a/packages/wmr/test/fixtures/prod-htm-index/public/foo.js b/packages/wmr/test/fixtures/prod-htm-index/public/foo.js new file mode 100644 index 000000000..3329a7d97 --- /dev/null +++ b/packages/wmr/test/fixtures/prod-htm-index/public/foo.js @@ -0,0 +1 @@ +export const foo = 'foo'; diff --git a/packages/wmr/test/fixtures/prod-htm-index/public/index.htm b/packages/wmr/test/fixtures/prod-htm-index/public/index.htm new file mode 100644 index 000000000..82b5f8718 --- /dev/null +++ b/packages/wmr/test/fixtures/prod-htm-index/public/index.htm @@ -0,0 +1,7 @@ + + + +

Hello wmr

+ + + diff --git a/packages/wmr/test/fixtures/prod-htm-index/public/index.js b/packages/wmr/test/fixtures/prod-htm-index/public/index.js new file mode 100644 index 000000000..eaf8f3ac3 --- /dev/null +++ b/packages/wmr/test/fixtures/prod-htm-index/public/index.js @@ -0,0 +1,3 @@ +import { foo } from './foo.js'; + +document.querySelector('h1').textContent = foo; diff --git a/packages/wmr/test/production.test.js b/packages/wmr/test/production.test.js index 56786be9c..10e3bb4c1 100644 --- a/packages/wmr/test/production.test.js +++ b/packages/wmr/test/production.test.js @@ -24,6 +24,24 @@ describe('production', () => { cleanup.length = 0; }); + it('should build with .htm index file', async () => { + await loadFixture('prod-htm-index', env); + instance = await runWmr(env.tmp.path, 'build'); + const code = await instance.done; + console.info(instance.output.join('\n')); + expect(code).toBe(0); + + const readdir = async f => (await fs.readdir(path.join(env.tmp.path, f))).filter(f => f[0] !== '.'); + const readfile = async f => await fs.readFile(path.join(env.tmp.path, 'dist', f), 'utf-8'); + + const files = await readdir('dist/'); + const js = files.find(f => f.endsWith('.js')); + const html = files.find(f => f.endsWith('.htm')); + + expect(await readfile(js)).toMatch(/['"]foo["']/); + expect(await readfile(html)).toMatch(/Hello wmr/); + }); + describe('demo app', () => { it('should serve the demo app', async () => { await loadFixture('../../../../examples/demo', env);