Created
February 2, 2017 17:28
-
-
Save chris-schmitz/f6dd6aa471113ad07ae83cced3e71d69 to your computer and use it in GitHub Desktop.
Pulling in Font-Awesome and Animate.css using Webpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the entry point used by webpack.config.js | |
// it's not necessarily how/where you need to pull in the styles, but | |
// it's where I typically pull them in. | |
import Vue from 'vue' | |
import App from './App.vue' | |
require('./global_style/main.scss') | |
new Vue({ | |
el: '#app', | |
render: h => h(App) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The font path used in the font-awesome package is relative to the package itself | |
// when you're pulling font awesome into your style file that path breaks b/c it's | |
// now starting from this file instead of from node_modules. | |
// You can override that path by setting this variable relative to the node_modules | |
// folder. When webpack is loading the scss file it uses (actually the sass loader | |
// prob uses) the tilde(~) character to say "starting at node_modules". | |
$fa-font-path: '~font-awesome/fonts'; | |
@import '~font-awesome/scss/font-awesome.scss'; | |
@import "~/animate.css/animate.css"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "1.0.0", | |
"author": "chris-schmitz <[email protected]>", | |
"private": true, | |
"scripts": { | |
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --inline --hot", | |
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules" | |
}, | |
"dependencies": { | |
"vue": "^2.1.0" | |
}, | |
"devDependencies": { | |
"animate.css": "^3.5.2", | |
"babel-core": "^6.0.0", | |
"babel-loader": "^6.0.0", | |
"babel-preset-es2015": "^6.0.0", | |
"cross-env": "^3.0.0", | |
"css-loader": "^0.25.0", | |
"file-loader": "^0.9.0", | |
"font-awesome": "^4.7.0", | |
"node-sass": "^4.5.0", | |
"sass-loader": "^4.1.1", | |
"style-loader": "^0.13.1", | |
"url-loader": "^0.5.7", | |
"vue-loader": "^10.0.0", | |
"vue-template-compiler": "^2.1.0", | |
"webpack": "^2.2.0", | |
"webpack-dev-server": "^2.2.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note that this includes loaders, configs, and rules that aren't necessarily required for bringing | |
// font-awesome and webpack in, but I want to give the full context in each file so there's no assumptions made. | |
var path = require('path') | |
var webpack = require('webpack') | |
module.exports = { | |
entry: './src/main.js', | |
output: { | |
path: path.resolve(__dirname, './dist'), | |
publicPath: '/dist/', | |
filename: 'build.js' | |
}, | |
module: { | |
rules: [ | |
// these three rules are the ones relevant to loading font-awesome and animate.css | |
{ | |
test: /\.scss$/, | |
loaders: ['style-loader', 'css-loader', 'sass-loader'], | |
exclude: /node_modules/ | |
}, | |
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" }, | |
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }, | |
// ==== | |
{ | |
test: /\.vue$/, | |
loader: 'vue-loader', | |
options: { | |
loaders: { | |
'scss': 'vue-style-loader!css-loader!sass-loader', | |
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax' | |
} | |
// other vue-loader options go here | |
} | |
}, | |
{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.(png|jpg|gif|svg)$/, | |
loader: 'file-loader', | |
options: { | |
name: '[name].[ext]?[hash]' | |
} | |
} | |
] | |
}, | |
resolve: { | |
alias: { | |
'vue$': 'vue/dist/vue.common.js' | |
} | |
}, | |
devServer: { | |
historyApiFallback: true, | |
noInfo: true | |
}, | |
performance: { | |
hints: false | |
}, | |
devtool: '#eval-source-map' | |
} | |
if (process.env.NODE_ENV === 'production') { | |
module.exports.devtool = '#source-map' | |
// http://vue-loader.vuejs.org/en/workflow/production.html | |
module.exports.plugins = (module.exports.plugins || []).concat([ | |
new webpack.DefinePlugin({ | |
'process.env': { | |
NODE_ENV: '"production"' | |
} | |
}), | |
new webpack.optimize.UglifyJsPlugin({ | |
sourceMap: true, | |
compress: { | |
warnings: false | |
} | |
}), | |
new webpack.LoaderOptionsPlugin({ | |
minimize: true | |
}) | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍