I am attempting to use Webpack 2 and Font Awesome in a Cordova application. The Cordova application generates a file structure like this:
app
config.xml
hooks
node_modules
package.json
platforms
plugins
webpack.config.js
www
(This naturally includes my NPM files and webpack configuration, for context. app
is where I squirrel away the raw JSX source code).
The structure under www
(which is where the compiled out web application should go), looks like this:
css
fonts
img
index.html
js
I created the fonts
directory as a target for the webpack configuration. The problem that I am running into is that I can either have the fonts copied to some useful location under the root or I can have the filtered CSS correct, but not both.
For example, if I use an example like the one below:
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader?name=[name].[ext]&outputPath=www/fonts/&publicPath=/fonts/"
}
The files get placed under www
, but the compiled source comes out strange.
@font-face {
font-family: 'FontAwesome';
src: url(/fonts/www/fonts/fontawesome-webfont.eot);
src: url(/fonts/www/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0) format('embedded-opentype'), url(/fonts/www/fonts/fontawesome-webfont.woff2) format('woff2'), url(/fonts/www/fonts/fontawesome-webfont.woff) format('woff'), url(/fonts/www/fonts/fontawesome-webfont.ttf) format('truetype'), url(/fonts/www/fonts/fontawesome-webfont.svg#fontawesomeregular) format('svg');
font-weight: normal;
font-style: normal;
}
I have yet to be able to find a happy medium with the file loader when trying to place fonts under www
. The recommendations in How to configure font file output directory from font-awesome-webpack in webpack? and Can't load font-awesome with Webpack really have not gotten me anywhere.