Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
928021b
commit 599bf72
Showing
7 changed files
with
299 additions
and
39 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"] | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,70 @@ | ||
'use strict'; | ||
const common = require('./webpack.common.js'); | ||
const { outputs } = require('./webpack.parts.js'); | ||
const path = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | ||
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); | ||
const { ProvidePlugin } = require('webpack'); | ||
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); | ||
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); | ||
|
||
const PRODUCTION = process.env.NODE_ENV === 'production'; | ||
module.exports = (env, argv) => { | ||
const isProduction = argv.mode === 'production'; | ||
|
||
// '[libraryTarget]': [file extension] | ||
const OUTPUT_MAPPING = { | ||
amd: 'amd', | ||
commonjs: 'cjs', | ||
commonjs2: 'cjs2', | ||
umd: 'umd', | ||
window: 'window', | ||
return { | ||
entry: './src/index.tsx', | ||
output: { | ||
filename: isProduction ? '[name].[contenthash].js' : '[name].js', | ||
path: path.resolve(__dirname, 'dist'), | ||
}, | ||
resolve: { | ||
extensions: ['.tsx', '.ts', '.js'], | ||
plugins: [new TsconfigPathsPlugin()], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: [ | ||
'@babel/preset-env', | ||
'@babel/preset-react', | ||
'@babel/preset-typescript', | ||
], | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: /\.(sa|sc|c)ss$/, | ||
use: [ | ||
isProduction ? MiniCssExtractPlugin.loader : 'style-loader', | ||
'css-loader', | ||
'sass-loader', | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new CleanWebpackPlugin(), | ||
new ProvidePlugin({ | ||
React: 'react', | ||
}), | ||
new ForkTsCheckerWebpackPlugin(), | ||
].concat( | ||
isProduction | ||
? [ | ||
new MiniCssExtractPlugin({ | ||
filename: '[name].[contenthash].css', | ||
}), | ||
] | ||
: [] | ||
), | ||
devtool: isProduction ? undefined : 'eval-cheap-module-source-map', | ||
devServer: { | ||
contentBase: path.join(__dirname, 'public'), | ||
compress: true, | ||
port: 3000, | ||
}, | ||
}; | ||
}; | ||
|
||
const OVERRIDES = { | ||
// optimization: { | ||
// minimize: false | ||
// } | ||
}; | ||
|
||
if (PRODUCTION) { | ||
module.exports = outputs(common, 'production', OUTPUT_MAPPING, OVERRIDES); | ||
} else { | ||
module.exports = outputs(common, 'development', OUTPUT_MAPPING, OVERRIDES); | ||
} |
Oops, something went wrong.