humus-old/webpack.common.config.js
2019-09-22 21:25:43 -05:00

153 lines
3.5 KiB
JavaScript

const path = require('path');
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
const globImporter = require('node-sass-glob-importer');
const webpack = require('webpack');
const isProduction = !!process.argv.find((arg) => '--production' === arg);
const config = {
mode: isProduction ? 'production' : 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: [
/(node_modules\/(?!@avocado|contempo))/,
],
use: {
loader: 'babel-loader',
options: {},
},
},
{
test: /register-packets\.js$/,
use: {
loader: './defgen',
options: {
classTransformer: (Packet) => {
return `${Packet}Packet`;
},
paths: [
path.resolve(__dirname, 'common'),
],
registrar: {
function: 'registerPacket',
module: '@avocado/net',
},
type: 'packet',
},
},
},
{
test: /register-synchronizeds\.js$/,
use: {
loader: './defgen',
options: {
paths: [
path.resolve(__dirname, 'common'),
],
registrar: {
function: 'registerSynchronized',
module: '@avocado/net',
},
type: 'synchronized',
},
},
},
{
test: /register-traits\.js$/,
use: {
loader: './defgen',
options: {
paths: [
path.resolve(__dirname, 'common'),
],
registrar: {
function: 'registerTrait',
module: '@avocado/entity',
},
type: 'trait',
},
},
},
// Styles.
{
test: /\.(?:sa|sc|c)ss$/,
exclude: /\.raw\./,
use: [
{
loader: ExtractCssChunks.loader,
options: {
hot: true,
},
},
{
loader: 'css-loader',
options: {
// 2 because postcss & sass.
importLoaders: 2,
},
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
options: {
importer: globImporter(),
},
},
],
},
{
test: /\.(?:sa|sc|c)ss$/,
include: /\.raw\./,
use: [
{
loader: 'raw-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
options: {
importer: globImporter(),
},
},
],
},
],
},
output: {
// Worker happiness.
globalObject: `(typeof self === 'undefined' ? this : self)`,
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
plugins: [
new ExtractCssChunks({
filename: '[name].css',
}),
],
resolve: {
alias: {
'register-packets': path.join(__dirname, 'register-packets'),
'register-synchronizeds': path.join(__dirname, 'register-synchronizeds'),
'register-traits': path.join(__dirname, 'register-traits'),
},
modules: [
path.join(__dirname, 'node_modules'),
path.join(__dirname, 'scss'),
],
},
resolveLoader: {
modules: [
path.join(__dirname, 'node_modules'),
],
},
};
module.exports = config;