Created
June 12, 2020 22:36
-
-
Save kucukkanat/0ae7dd0913358a8693e504b9bc513ec1 to your computer and use it in GitHub Desktop.
Webpack config for react libraries
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
// 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