Skip to content

Instantly share code, notes, and snippets.

@halfnibble
Created June 22, 2020 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halfnibble/4a8a14c5465558d2934ab2419777269a to your computer and use it in GitHub Desktop.
Save halfnibble/4a8a14c5465558d2934ab2419777269a to your computer and use it in GitHub Desktop.
Add file-loader to webpack config.
const path = require('path')
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin')
const { postLogin, postArticle } = require('./js/api')
const express = require('express')
module.exports = {
mode: 'development',
entry: {
'app': './js/index.js',
'styles': './sass/styles.sass'
},
module: {
rules: [
{
test: /\.(png|jpg|gif)$/,
include: [
path.resolve(__dirname, './img'),
],
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
},
{
test: /\.s[ac]ss$/i, // .scss or .sass
loader: ExtractTextWebpackPlugin.extract([
'css-loader',
'sass-loader'
])
}
]
},
plugins: [
new ExtractTextWebpackPlugin({
filename: '[name].css',
allChunks: true
})
],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
devServer: {
contentBase: __dirname,
publicPath: '/dist/',
port: 8080,
host: '0.0.0.0',
hot: true,
disableHostCheck: true,
before: (app, server, compiler) => {
app.use(express.json())
app.post('/api/login', postLogin)
app.post('/api/article', postArticle)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment