Skip to content

Instantly share code, notes, and snippets.

@taiansu
Created May 9, 2019 21:12
Show Gist options
  • Save taiansu/4691a2fe4e427e86f7f1ae9909644267 to your computer and use it in GitHub Desktop.
Save taiansu/4691a2fe4e427e86f7f1ae9909644267 to your computer and use it in GitHub Desktop.
Example webpack.config.js
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (env, options) => ({
optimization: {
minimizer: [
new UglifyJsPlugin({cache: true, parallel: true, sourceMap: false}),
new OptimizeCSSAssetsPlugin({})
]
},
entry: './js/app.js',
output: {
filename: 'app.js',
path: path.resolve(__dirname, '../priv/static/js')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
},
{
test: /\.(css|sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
plugins: () => [
require('autoprefixer')
],
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: '../fonts'
}
}]
},
{
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {name: '/images/[name].[ext]'}
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({filename: '../css/app.css'}),
new CopyWebpackPlugin([{from: 'static/', to: '../'}]),
new webpack.ProviderPlugin({
$: 'jquery',
R: 'ramda'
})
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment