From 568a7f4f58c19c81cdc957f044a559dff20c3d27 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 14 Oct 2019 20:38:37 +0200 Subject: [PATCH] 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 --- config/webpack.config.dev.js | 4 +++- config/webpack.config.prod.js | 13 ++++++------- package.json | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 9a7185bd..7af9fd93 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -83,7 +83,6 @@ module.exports = { extensions: ['.js', '.elm'] }, module: { - noParse: /\.elm$/, strictExportPresence: true, rules: [ // Disable require.ensure as it's not a standard language feature. @@ -168,6 +167,9 @@ module.exports = { flags: 'g' } }, + { + loader: require.resolve('elm-asset-webpack-loader') + }, { loader: require.resolve('elm-webpack-loader'), options: { diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js index 189b8e18..98ef98f7 100644 --- a/config/webpack.config.prod.js +++ b/config/webpack.config.prod.js @@ -142,8 +142,6 @@ module.exports = { module: { strictExportPresence: true, - noParse: /\.elm$/, - rules: [ { test: /\.js$/, @@ -220,6 +218,9 @@ module.exports = { flags: 'g' } }, + { + loader: require.resolve('elm-asset-webpack-loader') + }, { // Use the local installation of elm make loader: require.resolve('elm-webpack-loader'), @@ -339,16 +340,14 @@ module.exports = { publicPath: publicPath }), // Copies the public folder to the build folder - new CopyPlugin([ - { from: './public/', to: './' }, - ]), + new CopyPlugin([{ from: './public/', to: './' }]), // Generate a service worker script that will precache, and keep up to date, // the HTML & assets that are part of the Webpack build. new workboxPlugin.GenerateSW({ - swDest: "./service-worker.js", + swDest: './service-worker.js', skipWaiting: true, clientsClaim: true - }), + }) ], // Some libraries import Node modules but don't use them in the browser. // Tell Webpack to provide empty mocks for them so importing them works. diff --git a/package.json b/package.json index fb2caaac..e70d0379 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "cross-env": "^5.2.0", "cz-conventional-changelog": "^3.0.2", "dir-compare": "^1.4.0", + "elm-asset-webpack-loader": "1.1.1", "eslint": "^6.1.0", "eslint-plugin-prettier": "^3.1.0", "husky": "^3.0.3",