Last active
January 11, 2021 10:31
-
-
Save Robbie-Cook/96be95a2c459844e811bcd2208bb053e to your computer and use it in GitHub Desktop.
A Webpack config for compiling libraries (including React component libraries)
This file contains hidden or 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 nodeExternals = require("webpack-node-externals"); | |
| const path = require("path"); | |
| module.exports = { | |
| entry: path.resolve(__dirname, "./src/index.ts"), | |
| output: { | |
| path: path.resolve(__dirname, "./dist"), | |
| filename: "index.js", | |
| libraryTarget: "commonjs2" | |
| }, | |
| mode: "production", | |
| target: "web", | |
| // Enable sourcemaps for debugging webpack's output. | |
| devtool: "source-map", | |
| resolve: { | |
| // Add '.ts' and '.tsx' as resolvable extensions. | |
| extensions: [".ts", ".tsx", ".js", ".jsx"], | |
| }, | |
| module: { | |
| rules: [ | |
| { | |
| test: /(\.ts(x?))|(\.jsx?)$/, | |
| exclude: /node_modules/, | |
| use: [ | |
| { | |
| loader: "ts-loader", | |
| options: { | |
| configFile: path.resolve(__dirname, "tsconfig.json"), | |
| }, | |
| }, | |
| ], | |
| }, | |
| { | |
| test: /\.scss$/, | |
| exclude: /node_modules/, | |
| use: [ | |
| // Use the chain sass-loader -> css-loader -> style-loader | |
| // But use MiniCssExtractPlugin on prod, so we get a file. | |
| { | |
| loader: "style-loader", | |
| }, | |
| { | |
| loader: "css-loader", | |
| }, | |
| { | |
| loader: "sass-loader", | |
| }, | |
| ], | |
| }, | |
| ], | |
| }, | |
| // externals: { | |
| // 'react': 'react', // Case matters here | |
| // 'react-dom' : 'react-dom' // Case matters here | |
| // }, | |
| externals: [nodeExternals()], | |
| plugins: [], | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment