modules/stanford_news/webpack.config.js
const path = require("path");
const glob = require('glob')
const Webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const FileManagerPlugin = require('filemanager-webpack-plugin');
const autoprefixer = require('autoprefixer')({ grid: true });
const config = {
isProd: process.env.NODE_ENV === "production",
hmrEnabled: process.env.NODE_ENV !== "production" && !process.env.NO_HMR,
distFolder: path.resolve(__dirname, "./dist/css"),
wdsPort: 3001,
};
var webpackConfig = {
entry: {
"news-node": path.resolve("lib/scss/components/news-node/index.scss"),
"news-list-item": path.resolve("lib/scss/components/news-list-item/index.scss"),
"newsletter": path.resolve("lib/scss/components/newsletter/index.scss"),
"news-vertical-teaser": path.resolve("lib/scss/components/news-vertical-teaser/index.scss")
},
output: {
path: config.distFolder,
filename: '[name].js',
assetModuleFilename: '../assets/[name][ext][query]'
},
mode: config.isProd ? "production" : "development",
resolve: {
alias: {
'decanter-assets': path.resolve('node_modules', 'decanter/core/src/img'),
'decanter-src': path.resolve('node_modules', 'decanter/core/src'),
'@fortawesome': path.resolve('node_modules', '@fortawesome'),
'fa-fonts': path.resolve('node_modules', '@fortawesome/fontawesome-free/webfonts')
}
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [
config.isProd ? { loader: MiniCssExtractPlugin.loader } : 'style-loader',
{loader:'css-loader', options: {}},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
sourceMap: true,
plugins: [autoprefixer],
},
}
},
{loader:'sass-loader', options: {}}
]
},
{
test: /\.(png|jpg|gif|svg)$/i,
type: "asset"
}
]
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new FileManagerPlugin({
events: {
onStart: {
delete: ['dist'],
},
},
}),
],
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin(),
]
}
};
if (config.hmrEnabled) {
webpackConfig.plugins.push(new Webpack.HotModuleReplacementPlugin());
}
module.exports = webpackConfig;