Skip to content

Commit 568a7f4

Browse files
committed
feat(webpack config): elm-webpack-asset-loader to require assets
Resolves paths to assets in strings in Elm code with webpack. Example: ``` img [ src "require:src/assets/logo.svg" ] [] ``` Fixes #363
1 parent a86acd4 commit 568a7f4

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

config/webpack.config.dev.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ module.exports = {
8383
extensions: ['.js', '.elm']
8484
},
8585
module: {
86-
noParse: /\.elm$/,
8786
strictExportPresence: true,
8887
rules: [
8988
// Disable require.ensure as it's not a standard language feature.
@@ -168,6 +167,9 @@ module.exports = {
168167
flags: 'g'
169168
}
170169
},
170+
{
171+
loader: require.resolve('elm-asset-webpack-loader')
172+
},
171173
{
172174
loader: require.resolve('elm-webpack-loader'),
173175
options: {

config/webpack.config.prod.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ module.exports = {
142142
module: {
143143
strictExportPresence: true,
144144

145-
noParse: /\.elm$/,
146-
147145
rules: [
148146
{
149147
test: /\.js$/,
@@ -220,6 +218,9 @@ module.exports = {
220218
flags: 'g'
221219
}
222220
},
221+
{
222+
loader: require.resolve('elm-asset-webpack-loader')
223+
},
223224
{
224225
// Use the local installation of elm make
225226
loader: require.resolve('elm-webpack-loader'),
@@ -339,16 +340,14 @@ module.exports = {
339340
publicPath: publicPath
340341
}),
341342
// Copies the public folder to the build folder
342-
new CopyPlugin([
343-
{ from: './public/', to: './' },
344-
]),
343+
new CopyPlugin([{ from: './public/', to: './' }]),
345344
// Generate a service worker script that will precache, and keep up to date,
346345
// the HTML & assets that are part of the Webpack build.
347346
new workboxPlugin.GenerateSW({
348-
swDest: "./service-worker.js",
347+
swDest: './service-worker.js',
349348
skipWaiting: true,
350349
clientsClaim: true
351-
}),
350+
})
352351
],
353352
// Some libraries import Node modules but don't use them in the browser.
354353
// Tell Webpack to provide empty mocks for them so importing them works.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"cross-env": "^5.2.0",
7272
"cz-conventional-changelog": "^3.0.2",
7373
"dir-compare": "^1.4.0",
74+
"elm-asset-webpack-loader": "1.1.1",
7475
"eslint": "^6.1.0",
7576
"eslint-plugin-prettier": "^3.1.0",
7677
"husky": "^3.0.3",

0 commit comments

Comments
 (0)