Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
webpack-dev-service
Advanced tools
Readme
A koa 2 middleware for webpack development and hot reloading.
/**
* @module webpack
* @description Webpack config
*/
import Koa from 'koa';
import path from 'path';
import memfs from 'memfs';
import webpack from 'webpack';
import compress from 'koa-compress';
import dev from 'webpack-dev-service';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
const progress = {
percentBy: 'entries'
};
const entryHTML = path.resolve('public/index.html');
const html = {
xhtml: true,
minify: false,
title: 'React',
filename: entryHTML,
templateParameters: { lang: 'en' },
template: path.resolve('index.ejs'),
favicon: path.resolve('src/images/favicon.ico'),
meta: { 'theme-color': '#4285f4', viewport: 'width=device-width,initial-scale=1.0' }
};
function createMemfs() {
const volume = new memfs.Volume();
const fs = memfs.createFsFromVolume(volume);
return fs;
}
function httpError(error) {
return /^(EOF|EPIPE|ECANCELED|ECONNRESET|ECONNABORTED)$/i.test(error.code);
}
const compiler = webpack({
name: 'react',
mode: 'development',
context: path.resolve('src'),
entry: path.resolve('src/index.tsx'),
output: {
publicPath: '/public/',
filename: `js/[name].js`,
path: path.resolve('public'),
chunkFilename: `js/[name].js`,
assetModuleFilename: `[path][name][ext]`
},
devtool: 'eval-cheap-module-source-map',
resolve: {
fallback: { url: false },
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
watchOptions: {
aggregateTimeout: 256
},
stats: {
colors: true,
chunks: false,
children: false,
entrypoints: false,
runtimeModules: false,
dependentModules: false
},
plugins: [
new HtmlWebpackPlugin(html),
new MiniCssExtractPlugin({
ignoreOrder: true,
filename: 'css/[name].css',
chunkFilename: 'css/[name].css'
}),
new webpack.ProgressPlugin(progress)
],
module: {
strictExportPresence: true,
rules: [
{
oneOf: [
{
test: /\.[jt]sx?$/i,
exclude: /[\\/]node_modules[\\/]/,
use: [
{
loader: 'swc-loader',
options: {
jsc: {
externalHelpers: true,
parser: {
tsx: true,
syntax: 'typescript'
},
transform: {
react: {
runtime: 'automatic'
}
}
},
env: {
targets: ['defaults', 'not IE >= 0']
}
}
}
]
},
{
test: /\.css$/i,
exclude: /[\\/]node_modules[\\/]/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
esModule: true,
modules: {
auto: true,
localIdentName: '[local]-[hash:8]',
exportLocalsConvention: 'camelCaseOnly'
}
}
}
]
},
{
test: /\.(svg|mp4)$/i,
type: 'asset/resource',
exclude: /[\\/]node_modules[\\/]/
}
]
}
]
}
});
const port = 8000;
const app = new Koa();
const fs = createMemfs();
const server = dev(compiler, {
fs,
headers: {
'Cache-Control': 'no-cache',
'X-Content-Type-Options': 'nosniff'
}
});
app.use(
compress({
br: false
})
);
app.use(server);
app.use(async ctx => {
ctx.type = 'text/html; charset=utf-8';
ctx.body = fs.createReadStream(entryHTML);
});
app.on('error', error => {
!httpError(error) && console.error(error);
});
app.listen(port, () => {
server.ready(() => {
server.logger.info(`server run at: \u001B[36mhttp://127.0.0.1:${port}\u001B[0m`);
});
});
FAQs
A koa 2 middleware for webpack development and hot reloading.
The npm package webpack-dev-service receives a total of 3 weekly downloads. As such, webpack-dev-service popularity was classified as not popular.
We found that webpack-dev-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.