Created
June 22, 2020 17:23
-
-
Save halfnibble/4a8a14c5465558d2934ab2419777269a to your computer and use it in GitHub Desktop.
Add file-loader to webpack config.
This file contains 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
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