90 lines
1.9 KiB
JavaScript
90 lines
1.9 KiB
JavaScript
// Generated using webpack-cli https://github.com/webpack/webpack-cli
|
|
|
|
const path = require("path");
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
const WorkboxWebpackPlugin = require("workbox-webpack-plugin");
|
|
|
|
const isProduction = process.env.NODE_ENV == "production";
|
|
|
|
const minimiseCSS = isProduction ? "compressed" : "expanded";
|
|
|
|
const config = {
|
|
entry:{ "scripts": "./src/js/app.js",
|
|
"styles": "./src/scss/styles.scss"},
|
|
output: {
|
|
path: path.resolve(__dirname, "public"),
|
|
},
|
|
devServer: {
|
|
open: true,
|
|
host: "localhost",
|
|
},
|
|
optimization: {
|
|
minimize: false,
|
|
},
|
|
plugins: [
|
|
new HtmlWebpackPlugin({
|
|
template: "src/index.html",
|
|
}),
|
|
|
|
// 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: /\.s[ac]ss$/i,
|
|
use: [
|
|
{
|
|
loader: MiniCssExtractPlugin.loader
|
|
},
|
|
{
|
|
loader: "css-loader",
|
|
},
|
|
{
|
|
loader: 'sass-loader',
|
|
options: {
|
|
sassOptions: {
|
|
outputStyle: minimiseCSS,
|
|
}
|
|
}
|
|
},
|
|
],
|
|
},
|
|
{
|
|
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
|
|
use: {
|
|
loader: "file-loader",
|
|
options: {
|
|
name: "[name].[ext]",
|
|
outputPath: "assets",
|
|
},
|
|
},
|
|
},
|
|
|
|
// Add your rules for custom modules here
|
|
// Learn more about loaders from https://webpack.js.org/loaders/
|
|
],
|
|
},
|
|
};
|
|
|
|
module.exports = () => {
|
|
if (isProduction) {
|
|
config.mode = "production";
|
|
config.plugins.push(new MiniCssExtractPlugin({
|
|
filename: "style.min.css",
|
|
}));
|
|
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
|
|
} else {
|
|
config.plugins.push(new MiniCssExtractPlugin({
|
|
filename: "style.css",
|
|
}));
|
|
config.mode = "development";
|
|
}
|
|
return config;
|
|
};
|