From 1c4df2be0b5ff437c23f7ca99b99bf93c3cf1666 Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Wed, 2 Oct 2024 09:08:45 -0400 Subject: [PATCH] STRWEB-109 allow loading of arbitrary text files (#145) Support `?raw` to load arbitrary text files as strings, permitting, for example, a large XSLT file to be easily imported. Usage: ``` import txtFile from "./someTxtFile.txt?raw" ``` Refs STRWEB-109 --- CHANGELOG.md | 1 + webpack.config.base.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6c4ab6..ff36bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Don't worry about the order of CSS imports across modules. Refs STRWEB-110. * Remove postcss-plugins: postcss-nesting, postcss-custom-properties, postcss-color-function, postcss-calc. Add CSS variables entry point in webpack config. Refs STRWEB-111. +* Support import of arbitrary text files via `?raw`. Refs STRWEB-109. ## [5.1.0](https://github.com/folio-org/stripes-webpack/tree/v5.1.0) (2024-03-12) [Full Changelog](https://github.com/folio-org/stripes-webpack/compare/v5.0.0...v5.1.0) diff --git a/webpack.config.base.js b/webpack.config.base.js index ffb74fa..0be1037 100644 --- a/webpack.config.base.js +++ b/webpack.config.base.js @@ -117,6 +117,16 @@ const baseConfig = { resourceQuery: /icon/, // stcom icons use this query on the resource. use: ['@svgr/webpack'] }, + // allow import of arbitrary files as strings by appending `?raw` to the import. + // use it like: + // import someString from "./someTxtFile.txt?raw" + // see https://github.com/webpack/webpack/discussions/16775#discussioncomment-5233250 + // see https://webpack.js.org/guides/asset-modules/ + // this facilitates importing large files as strings, e.g. XSLT + { + type: 'asset/source', + resourceQuery: /raw/, + }, ], }, };