Skip to content

Instantly share code, notes, and snippets.

@kino6052
Created October 27, 2018 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kino6052/c636acdd47322fda7bb6eaf273550843 to your computer and use it in GitHub Desktop.
Save kino6052/c636acdd47322fda7bb6eaf273550843 to your computer and use it in GitHub Desktop.
webpack-configuration-example
const path = require( 'path' );
const webpack = require( 'webpack' );
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = ( env, options ) => {
return {
entry: './src/block.js',
output: {
path: path.resolve( __dirname, 'build' ),
filename: 'block.js',
},
devtool: 'cheap-eval-source-map',
module: {
rules: [
{
test: /\.jsx$|\.es6$|\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['react'],
}
},
exclude: /(node_modules|bower_components)/
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: ( options.mode == 'production' ? true : false ),
sourceMap: true,
}
},
{
loader: 'postcss-loader',
options: {
plugins: [ require( 'autoprefixer' ) ]
}
},
],
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/'
}
}
]
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'style.css',
chunkFilename: '[id].css'
})
],
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment