Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Nov 2, 2024
1 parent c4c5d76 commit a8de9f3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 110 deletions.
55 changes: 2 additions & 53 deletions test/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,8 @@
import HtmlBundlerPlugin from "html-bundler-webpack-plugin";
import { join, resolve } from "path";
import webpack, { type Stats } from "webpack";
import { createWebpackConfig } from "./create-webpack-config.js";

export default (fixture: string): Promise<Stats> => {
const compiler = webpack({
mode: "production",
devtool: "source-map",
context: join(import.meta.dirname, "fixture", fixture),
output: {
path: resolve(import.meta.dirname, "../artifacts/test/output", fixture),
filename: "bundle.js",
publicPath: "/path/to/public/",
assetModuleFilename: "[name].public[ext][query]",
},
plugins: [
new HtmlBundlerPlugin({
entry: {
index: "index.html",
},
loaderOptions: {
sources: [
{
tag: "meta",
attributes: ["content"],
filter: ({ attributes: { name } }) =>
name === "msapplication-config" ||
name === "msapplication-TileImage",
},
],
},
}),
],
module: {
rules: [
{
test: /\.(png|xml)$/,
type: "asset/resource",
},
{
test: /\/browserconfig\.xml$/i,
type: "asset/resource",
use: resolve(import.meta.dirname, "../artifacts/dist/esm/index.js"),
},
{
test: /\/notification-[135]\.xml$/i,
type: "asset/resource",
generator: {
emit: false,
filename: "[name][ext]",
publicPath: "https://cdn.example.com/",
},
},
],
},
});
const compiler = webpack(createWebpackConfig(fixture));

return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
Expand Down
3 changes: 3 additions & 0 deletions test/create-webpack-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Configuration } from "webpack";

declare function createWebpackConfig(fixture: string): Configuration;
61 changes: 61 additions & 0 deletions test/create-webpack-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import HtmlBundlerPlugin from "html-bundler-webpack-plugin";
import { resolve } from "path";

/**
* @param {string} fixture
* @returns {import('webpack').Configuration}
*/
export function createWebpackConfig(fixture) {
return {
mode: "production",
devtool: "source-map",
context: resolve(import.meta.dirname, "fixture", fixture),
entry: "./index.html",
output: {
path: resolve(import.meta.dirname, "../artifacts/integration"),
filename: "bundle.js",
publicPath: "/path/to/public/",
assetModuleFilename: "[name].public[ext][query]",
},
plugins: [
new HtmlBundlerPlugin({
entry: {
index: "index.html",
},
loaderOptions: {
sources: [
{
tag: "meta",
attributes: ["content"],
filter: ({ attributes: { name } }) =>
name === "msapplication-config" ||
name === "msapplication-TileImage",
},
],
},
}),
],
module: {
rules: [
{
test: /\.(png|xml)$/,
type: "asset/resource",
},
{
test: /\/browserconfig\.xml$/i,
type: "asset/resource",
use: resolve(import.meta.dirname, "../artifacts/dist/esm/index.js"),
},
{
test: /\/notification-[135]\.xml$/i,
type: "asset/resource",
generator: {
emit: false,
filename: "[name][ext]",
publicPath: "https://cdn.example.com/",
},
},
],
},
};
}
59 changes: 2 additions & 57 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,7 @@
import HtmlBundlerPlugin from "html-bundler-webpack-plugin";
import { resolve } from "path";
import { createWebpackConfig } from "./create-webpack-config.js";

const fixture = process.env.FIXTURE;

if (!fixture) throw new Error("FIXTURE is required");

/** @type {import('webpack').Configuration} */
const config = {
mode: "production",
devtool: "source-map",
context: resolve(import.meta.dirname, "fixture", fixture),
entry: "./index.html",
output: {
path: resolve(import.meta.dirname, "../artifacts/integration"),
filename: "bundle.js",
publicPath: "/path/to/public/",
assetModuleFilename: "[name].public[ext][query]",
},
plugins: [
new HtmlBundlerPlugin({
entry: {
index: "index.html",
},
loaderOptions: {
sources: [
{
tag: "meta",
attributes: ["content"],
filter: ({ attributes: { name } }) =>
name === "msapplication-config" ||
name === "msapplication-TileImage",
},
],
},
}),
],
module: {
rules: [
{
test: /\.(png|xml)$/,
type: "asset/resource",
},
{
test: /\/browserconfig\.xml$/i,
type: "asset/resource",
use: resolve(import.meta.dirname, "../artifacts/dist/esm/index.js"),
},
{
test: /\/notification-[135]\.xml$/i,
type: "asset/resource",
generator: {
emit: false,
filename: "[name][ext]",
publicPath: "https://cdn.example.com/",
},
},
],
},
};

export default config;
export default createWebpackConfig(fixture);

0 comments on commit a8de9f3

Please sign in to comment.