Skip to content

Instantly share code, notes, and snippets.

@kucukkanat
Created June 12, 2020 22:36
Show Gist options
  • Save kucukkanat/0ae7dd0913358a8693e504b9bc513ec1 to your computer and use it in GitHub Desktop.
Save kucukkanat/0ae7dd0913358a8693e504b9bc513ec1 to your computer and use it in GitHub Desktop.
Webpack config for react libraries
// yarn add webpack webpack-cli typescript ts-loader mini-css-extract-plugin sass sass-loader style-loader css-loader
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
devtool: "source-map", // any "source-map"-like devtool is possible
entry: path.resolve(__dirname, "src/index.tsx"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
library: "myLib",
libraryTarget: "umd",
globalObject: "this"
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "ts-loader" },
{
test: /\.s[ac]ss$/i,
use: [
"style-loader",
{
loader: MiniCssExtractPlugin.loader
},
{
loader: "css-loader",
options: {
sourceMap: true
}
},
{
loader: "sass-loader",
options: {
sourceMap: true
}
}
]
}
]
},
plugins: [new MiniCssExtractPlugin()],
externals: ["react"]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment