Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zgordon
Created September 14, 2018 16:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zgordon/9295badd8b97fb28deb6d52b79cc9516 to your computer and use it in GitHub Desktop.
Save zgordon/9295badd8b97fb28deb6d52b79cc9516 to your computer and use it in GitHub Desktop.
A Gutenberg webpack configuration file
const path = require( 'path' );
const webpack = require( 'webpack' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
// Set different CSS extraction for editor only and common block styles
const blocksCSSPlugin = new ExtractTextPlugin( {
filename: './assets/css/blocks.style.css',
} );
const editBlocksCSSPlugin = new ExtractTextPlugin( {
filename: './assets/css/blocks.editor.css',
} );
// Configuration for the ExtractTextPlugin.
const extractConfig = {
use: [
{ loader: 'raw-loader' },
{
loader: 'postcss-loader',
options: {
plugins: [ require( 'autoprefixer' ) ],
},
},
{
loader: 'sass-loader',
query: {
outputStyle:
'production' === process.env.NODE_ENV ? 'compressed' : 'nested',
},
},
],
};
module.exports = {
entry: {
'./assets/js/editor.blocks' : './blocks/index.js',
'./assets/js/frontend.blocks' : './blocks/frontend.js',
},
output: {
path: path.resolve( __dirname ),
filename: '[name].js',
},
watch: 'production' !== process.env.NODE_ENV,
devtool: 'cheap-eval-source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
{
test: /style\.s?css$/,
use: blocksCSSPlugin.extract( extractConfig ),
},
{
test: /editor\.s?css$/,
use: editBlocksCSSPlugin.extract( extractConfig ),
},
],
},
plugins: [
blocksCSSPlugin,
editBlocksCSSPlugin,
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment