Skip to content
Permalink
Browse files

Fix webpack transforms for different install methods

The directory structure of npm dependencies is different
depending on whether auspice is installed from source, a
global npm install or a project's dependency. E.g. for webpack
to process the `font-awesome` dependency, then:
Global install & from source: `${__dirname}/node_modules/font-awesome`
Project dependency:           `${__dirname}/../font-awesome`

This bug comes from #826 which specified the first of the above
two scenarios.

Tested with projects using auspice (incl client-side customisations)
via global npm auspice isntall, npm dependency and `npm link <path>`
  • Loading branch information
jameshadfield committed Nov 27, 2019
1 parent ca61370 commit 934c6afbc69feb50aa614d9f3659787e0c29d5e9
Showing with 17 additions and 3 deletions.
  1. +17 −3 webpack.config.js
@@ -14,6 +14,22 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
/* which directories should be parsed by babel and other loaders? */
const directoriesToTransform = [path.join(__dirname, 'src')];

/* which font modules need to be able to be loaded by auspice? */
const fontModules = ["font-awesome", "leaflet", "typeface-lato"];
/* note that the directory structure is different depending on whether auspice
is installed from source, a global npm install or a project's dependency. E.g.
Global install & from source: `${__dirname}/node_modules/font-awesome`
Project dependency: `${__dirname}/../font-awesome`
This implementation is a short-term solution and should be improved */
let fileLoaderDirectoriesToTransform;
if (fs.existsSync(path.join(__dirname, "node_modules", fontModules[0]))) {
// global npm install or install from source
fileLoaderDirectoriesToTransform = fontModules.map((d) => path.join(__dirname, "node_modules", d));
} else {
// auspice is a project's dependency
fileLoaderDirectoriesToTransform = fontModules.map((d) => path.join(__dirname, "..", d));
}

/* webpack alias' used in code import / require statements */
const aliasesToResolve = {
"@extensions": '.', /* must provide a default, else it won't compile */
@@ -121,9 +137,7 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
use: "file-loader",
include: [
...directoriesToTransform,
path.join(__dirname, 'node_modules/font-awesome'),
path.join(__dirname, 'node_modules/leaflet'),
path.join(__dirname, 'node_modules/typeface-lato')
...fileLoaderDirectoriesToTransform
]
}
]

0 comments on commit 934c6af

Please sign in to comment.
You can’t perform that action at this time.