jgiven-html-app
Version:
The HTML App of JGiven and JsGiven
95 lines (92 loc) • 2.97 kB
JavaScript
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ENV = process.env.npm_lifecycle_event;
const isTest = ENV === 'test' || ENV === 'test-watch';
const isRelease = ENV === 'build';
module.exports = {
entry: {
styles: './src/css/styles.scss',
app: './src/js/app.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
isRelease ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
autoprefixer({
overrideBrowserslist: ['last 2 versions']
})
]
}
}
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.scss$/,
use: [
isRelease ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.(svg|woff|woff2|ttf|eot)$/,
type: 'asset/resource'
}
]
},
resolve: {
modules: ['node_modules']
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src/public/index.html'),
scriptLoading: 'blocking',
inject: false,
version: require("./package.json").version
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
ignoreOrder: false
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/)
],
devtool: isTest ? 'inline-source-map' : isRelease ? 'source-map' : 'eval-source-map',
devServer: {
static: path.join(__dirname, 'src/public'),
compress: true,
port: 9000,
},
stats: {
colors: true,
reasons: true,
chunks: true
}
};