mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-03-22 01:34:20 -05:00
93 lines
2.1 KiB
JavaScript
93 lines
2.1 KiB
JavaScript
const path = require('path');
|
|
const webpack = require('webpack');
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
require('@babel/register');
|
|
|
|
const devMode = (process.env.NODE_ENV !== 'production' && process.argv.indexOf('-p') === -1);
|
|
|
|
const config = {
|
|
entry: ['@babel/polyfill', `${__dirname}/src/components/index.js`],
|
|
|
|
output: {
|
|
path: `${__dirname}/build`,
|
|
publicPath: '/build/',
|
|
filename: 'bundle.js',
|
|
},
|
|
|
|
optimization: {
|
|
minimizer: [
|
|
new UglifyJsPlugin({
|
|
cache: true,
|
|
parallel: true,
|
|
sourceMap: true,
|
|
extractComments: true
|
|
}),
|
|
new OptimizeCSSAssetsPlugin({})
|
|
],
|
|
splitChunks: {
|
|
cacheGroups: {
|
|
styles: {
|
|
name: 'styles',
|
|
test: /\.css$/,
|
|
chunks: 'all',
|
|
enforce: true
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.(js|jsx)$/,
|
|
exclude: /node_modules/,
|
|
loader: 'babel-loader',
|
|
options: {
|
|
'presets': [
|
|
'@babel/preset-env',
|
|
'@babel/preset-react',
|
|
'@babel/preset-flow',
|
|
],
|
|
'plugins': [
|
|
'@babel/plugin-transform-runtime',
|
|
['@babel/plugin-proposal-decorators', {'legacy': true }],
|
|
['@babel/plugin-proposal-class-properties', { 'loose': true }]
|
|
]
|
|
}
|
|
},
|
|
{
|
|
test: /\.s?[ac]ss$/,
|
|
use: [
|
|
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
'css-loader',
|
|
'sass-loader',
|
|
],
|
|
}
|
|
]
|
|
},
|
|
|
|
resolve: {
|
|
extensions: ['.js', '.jsx'],
|
|
},
|
|
|
|
node: {
|
|
fs: 'empty',
|
|
},
|
|
|
|
// First array is dev only, second is production
|
|
plugins: devMode ? [] : [
|
|
new webpack.DefinePlugin({
|
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: '[name].css',
|
|
chunkFilename: '[id].css',
|
|
})
|
|
],
|
|
};
|
|
|
|
// Exports
|
|
module.exports = config;
|