Files
adminkit/webpack.config.js
T
Paul Laros a0801b0865 Init
2020-03-21 21:23:46 +01:00

155 lines
3.7 KiB
JavaScript

const Webpack = require("webpack");
const Path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");
const FileManagerPlugin = require("filemanager-webpack-plugin");
const opts = {
rootDir: process.cwd(),
devBuild: process.env.NODE_ENV !== "production"
};
module.exports = {
entry: {
app: "./src/js/app.js"
},
mode: process.env.NODE_ENV === "production" ? "production" : "development",
devtool:
process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map",
output: {
path: Path.join(opts.rootDir, "dist"),
pathinfo: opts.devBuild,
filename: "js/[name].js",
chunkFilename: 'js/[name].js',
},
performance: { hints: false },
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 5
}
}),
new OptimizeCSSAssetsPlugin({})
],
runtimeChunk: false,
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
enforce: true
}
}
}
},
plugins: [
// Extract css files to seperate bundle
new MiniCssExtractPlugin({
filename: "css/app.css",
chunkFilename: "css/app.css"
}),
// jQuery and PopperJS
new Webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
jquery: "jquery",
"window.$": "jquery",
"window.jQuery": "jquery",
Popper: ["popper.js", "default"]
}),
// Copy fonts and images to dist
new CopyWebpackPlugin([
{ from: "src/fonts", to: "fonts" },
{ from: "src/img", to: "img" }
]),
// Speed up webpack build
new HardSourceWebpackPlugin(),
// Copy dist folder to examples
new FileManagerPlugin({
onEnd: {
copy: [{ source: "./dist/**/*", destination: "./examples" }]
}
})
],
module: {
rules: [
// Babel-loader
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: ["babel-loader?cacheDirectory=true"]
},
// Css-loader & sass-loader
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"sass-loader"
]
},
// Load fonts
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "/[name].[ext]",
outputPath: "fonts/",
publicPath: "../fonts/"
}
}
]
},
// Load images
{
test: /\.(png|jpg|jpeg|gif)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "img/",
publicPath: "../img/"
}
}
]
},
// Expose loader
{
test: require.resolve("jquery"),
use: [
{
loader: "expose-loader",
options: "jQuery"
},
{
loader: "expose-loader",
options: "$"
}
]
}
]
},
resolve: {
extensions: [".js", ".scss"],
modules: ["node_modules"],
alias: {
request$: "xhr"
}
},
devServer: {
contentBase: Path.join(__dirname, "examples"),
compress: true,
port: 8080,
open: true
}
};