91 lines
2.8 KiB
JavaScript
91 lines
2.8 KiB
JavaScript
import path from 'path'
|
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
import { fileURLToPath } from 'url'
|
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
|
const isProduction = process.env.NODE_ENV == 'production';
|
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
const _myFileName = fileURLToPath(import.meta.url)
|
|
const _myDirName = path.dirname(_myFileName)
|
|
|
|
import webpack from 'webpack'
|
|
|
|
const config = {
|
|
entry: [
|
|
'./src/index.ts',
|
|
'./src/sass/player.sass',
|
|
],
|
|
devtool: isProduction ? false : 'inline-source-map',
|
|
output: {
|
|
path: path.resolve(_myDirName, 'dist'),
|
|
filename: isProduction ? '[name]-[chunkhash:6].js' : '[name].js',
|
|
},
|
|
devServer: {
|
|
open: true,
|
|
host: 'localhost',
|
|
},
|
|
resolve: {
|
|
extensions: ['.tsx', '.ts', '.js'],
|
|
fallback: {
|
|
// make it shut up about missing nodejs plugins in the browser
|
|
util: false,
|
|
}
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
template: 'index.html',
|
|
}),
|
|
// Turn this on only when you need an overview about the bundle contents
|
|
// new BundleAnalyzerPlugin(),
|
|
new MiniCssExtractPlugin({
|
|
filename: isProduction ? 'stylesheets/[name]-[contenthash:6].css' : 'stylesheets/[name].css',
|
|
}),
|
|
// Use this so it wont load extra chunks deferred, which breaks
|
|
// embedding the main.js script into a hugo site, for example
|
|
new webpack.optimize.LimitChunkCountPlugin({
|
|
maxChunks: 1,
|
|
})
|
|
// new NodePolyfillPlugin({
|
|
// excludeAliases: ['console'],
|
|
// }),
|
|
// Add your plugins here
|
|
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(js|jsx)$/i,
|
|
loader: 'babel-loader',
|
|
},
|
|
{
|
|
test: /\.(ts|tsx)$/i,
|
|
use: 'ts-loader',
|
|
exclude: /node_modules/,
|
|
},
|
|
{
|
|
test: /\.s[ac]ss$/i,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
|
|
},
|
|
{
|
|
test: /\.css$/i,
|
|
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
|
|
},
|
|
{
|
|
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
|
|
type: 'asset',
|
|
},
|
|
|
|
// Add your rules for custom modules here
|
|
// Learn more about loaders from https://webpack.js.org/loaders/
|
|
],
|
|
},
|
|
};
|
|
|
|
export default () => {
|
|
if (isProduction) {
|
|
config.mode = 'production';
|
|
} else {
|
|
config.mode = 'development';
|
|
}
|
|
return config;
|
|
};
|