Skip to content

Commit 2a263ff

Browse files
committed
feat: support arraybuffer-loader through ?arrayBuffer resource query
1 parent 31a9cd5 commit 2a263ff

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

package-lock.json

+39-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"peerDependencies": {
4646
"@babel/preset-env": "^7.24.0",
47+
"arraybuffer-loader": "^1.0.8",
4748
"autoprefixer": "^9.0.1",
4849
"babel-loader": "^9.1.3",
4950
"css-loader": "5.2.7",

src/index.cjs

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nodeExternals = require('webpack-node-externals');
55
const webpack = require('webpack');
66

77
const DEFAULT_CHUNK_FILENAME = 'chunks/[name].[chunkhash].js';
8+
const DEFAULT_ASSET_FILENAME = 'assets/[name].[hash][ext][query]';
89

910
/**
1011
* @typedef {import('webpack').Configuration} Configuration
@@ -70,6 +71,7 @@ class ScratchWebpackConfigBuilder {
7071
output: {
7172
clean: true,
7273
filename: '[name].js',
74+
assetModuleFilename: DEFAULT_ASSET_FILENAME,
7375
chunkFilename: DEFAULT_CHUNK_FILENAME,
7476
path: this._distPath,
7577
library: {
@@ -116,26 +118,39 @@ class ScratchWebpackConfigBuilder {
116118
{
117119
// `asset` automatically chooses between exporting a data URI and emitting a separate file.
118120
// Previously achievable by using `url-loader` with asset size limit.
119-
resourceQuery: /^\?asset$/,
121+
// If file output is chosen, it is saved with the default asset module filename.
122+
resourceQuery: '?asset',
120123
type: 'asset'
121124
},
122125
{
123126
// `asset/resource` emits a separate file and exports the URL.
124127
// Previously achievable by using `file-loader`.
128+
// Output is saved with the default asset module filename.
125129
resourceQuery: /^\?(resource|file)$/,
126130
type: 'asset/resource'
127131
},
128132
{
129133
// `asset/inline` exports a data URI of the asset.
130134
// Previously achievable by using `url-loader`.
135+
// Because the file is inlined, there is no filename.
131136
resourceQuery: /^\?(inline|url)$/,
132137
type: 'asset/inline'
133138
},
134139
{
135140
// `asset/source` exports the source code of the asset.
136141
// Previously achievable by using `raw-loader`.
137142
resourceQuery: /^\?(source|raw)$/,
138-
type: 'asset/source'
143+
type: 'asset/source',
144+
generator: {
145+
// This filename seems unused, but if it ever gets used,
146+
// its extension should not match the asset's extension.
147+
filename: DEFAULT_ASSET_FILENAME + '.js'
148+
}
149+
},
150+
{
151+
resourceQuery: '?arrayBuffer',
152+
type: 'javascript/auto',
153+
use: 'arraybuffer-loader'
139154
},
140155
{
141156
test: /\.hex$/,

0 commit comments

Comments
 (0)