Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save macouella/b913607cca3d9bfa2640ce26e1db7373 to your computer and use it in GitHub Desktop.
Save macouella/b913607cca3d9bfa2640ce26e1db7373 to your computer and use it in GitHub Desktop.
Somethings gotta give webpack
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const BrowserSyncPlugin = require("browser-sync-webpack-plugin");
const devMode = process.env.NODE_ENV !== "production";
const path = require("path");
module.exports = {
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true
// sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({}),
new CopyWebpackPlugin([{ from: "./src/img", to: "img" }], {})
]
},
entry: {
main: "./src",
style: "./src/style.sass"
},
output: {
path: path.resolve(__dirname, "dist/assets")
},
module: {
rules: [
{
test: /\.s[a|c]ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "sass-loader",
options: {
indentedSyntax: true
}
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[id].css"
}),
new BrowserSyncPlugin(
// BrowserSync options
{
// browse to http://localhost:3000/ during development
host: "localhost",
port: 3000,
// proxy the Webpack Dev Server endpoint
// (which should be serving on http://localhost:8100/)
// through BrowserSync
proxy: "http://localhost:8100/"
}
)
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment