
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
webpack-kit
Advanced tools
Make your webpack.config.js much simpler! Webpack KIT prepare preconfigured webpack config for you with:
Make your webpack.config.js much simpler! Webpack KIT prepare preconfigured webpack config for you with:
Webpack KIT also provides preconfigured WebpackDevServer and WebpackDevMiddleware with Hot Reload support. You can use Webpack KIT for frontend and backend compilation. This kit is opinionated about the configuration of webpack, but not about a configuration of Babel, ESlint, TSLint, Stylelint, PostCSS and TypeScript. You can configure all of that by yourself. Just create the configuration file, and Webpack KIT will set webpack configuration accordingly. If you use typescript, don't forget to create tsconfig.json
file.
Webpack KIT exports config
function with the following parameters:
@param config
: specify your entry, output and overwrite any defaults with your settings. It uses webpack-merge
with smart
strategy under the hood.@param argv
: This describes the options passed to webpack, same as argv
in https://webpack.js.org/configuration/configuration-types/#exporting-a-function@returns
webpack configuration object.Example:
const { config } = require("webpack-kit");
// returns configuration function with HMR and profiling enabled
const myConfig = config(
{ entry: "src/index.js" },
{ profile: true, hot: true }
);
// returns configuration object with development mode and HMR enabled
myConfig("development", { hot: true });
You can run webpack-kit even without any configuration, just run:
npx webpack-kit --entry ./src/main.js --output-path ./dist/ --watch
or add npm scripts to your package.json
, e.g.:
{
"scripts": {
"watch": "webpack-kit --entry ./src/main.js --output-path ./dist/ --watch",
"build": "webpack-kit --entry ./src/main.js --output-path ./dist/"
}
}
npm install webpack-kit --save-dev
or
yarn add -D webpack-kit
When you don't need to improve default configuration, you can run webpack-kit directly:
npx webpack-kit --help
All attributes are same like for webpack-cli, webpack-kit just load prepared configuration for all you need to build your project.
To compile frontend code, create webpack.config.js
file with following content:
const path = require("path");
const { config } = require("webpack-kit");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = (mode = "production", argv = {}) =>
config(
{
mode,
entry: {
client: path.resolve(__dirname, "src/client/index.tsx")
},
output: {
path: path.resolve(__dirname, "build/public")
},
devServer: {
port: 3000,
host: "localhost"
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve("src/public/index.html"),
title: "My Awesome Application"
})
]
},
argv
);
Optionally create configuration files for Babel, PostCSS, ESlint, Stylelint or TSlint.
To compile backend code, create webpack.config.js
file with following content:
const path = require("path");
const { config } = require("webpack-kit");
module.exports = (mode = "production", argv = {}) =>
config(
{
mode,
target: "node",
entry: {
server: path.resolve(__dirname, "src/server/index.js")
},
output: {
path: path.resolve(__dirname, "build")
}
},
argv
);
Please don't forget to specify the target
: node
. Optionally create configuration files for babel, ESlint or TSlint.
To use Webpack Dev Middleware, put following code to your server.js
file should look like this:
const express = require("express");
const app = express();
// Use webpack-dev-middleware in development only
if (process.env.NODE_ENV === "development") {
// Load configuration from your webpack.config.js file
const webpackConfig = require("../../webpack.config");
// Import webpack-dev-middleware
const { devMiddleware } = require("webpack-kit");
// Use webpack-dev-middleware in your express.
// If you pass `hot` argument, it will also use webpack-hot-middleware and configure entrypoints correctly
app.use(devMiddleware(webpackConfig("development", { hot: true })));
}
// Serve compiled static files from the build folder
app.use(
express.static("./build/public", {
index: false,
redirect: false,
maxAge: "1y"
})
);
// Fallback is built index.html, so your SPA works even after reload
app.use((req, res) => {
res.sendFile(resolve(process.cwd(), "./build/public/index.html"));
});
// Start the server
app.listen(port, () =>
console.log(`Listening at http://${process.env.HOST}:${process.env.PORT}`)
);
FAQs
Make your webpack.config.js much simpler! Webpack KIT prepare preconfigured webpack config for you with:
The npm package webpack-kit receives a total of 0 weekly downloads. As such, webpack-kit popularity was classified as not popular.
We found that webpack-kit demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.