humus-old/webpack.common.config.js

153 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-03-20 15:28:18 -05:00
const path = require('path');
2019-09-22 21:25:43 -05:00
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
const globImporter = require('node-sass-glob-importer');
2019-03-20 15:28:18 -05:00
const webpack = require('webpack');
2019-05-05 04:27:18 -05:00
const isProduction = !!process.argv.find((arg) => '--production' === arg);
2019-03-20 15:28:18 -05:00
const config = {
2019-05-05 04:27:18 -05:00
mode: isProduction ? 'production' : 'development',
2019-03-20 15:28:18 -05:00
module: {
rules: [
{
test: /\.js$/,
exclude: [
2019-04-12 11:04:59 -05:00
/(node_modules\/(?!@avocado|contempo))/,
2019-03-20 15:28:18 -05:00
],
use: {
loader: 'babel-loader',
2019-05-05 17:03:15 -05:00
options: {},
2019-03-20 15:28:18 -05:00
},
},
2019-04-14 21:32:48 -05:00
{
2019-04-25 00:09:28 -05:00
test: /register-packets\.js$/,
2019-04-14 21:32:48 -05:00
use: {
loader: './defgen',
options: {
classTransformer: (Packet) => {
return `${Packet}Packet`;
},
paths: [
path.resolve(__dirname, 'common'),
],
registrar: {
function: 'registerPacket',
2019-04-24 18:02:13 -05:00
module: '@avocado/net',
2019-04-14 21:32:48 -05:00
},
type: 'packet',
},
},
},
2019-09-22 18:45:52 -05:00
{
test: /register-synchronizeds\.js$/,
use: {
loader: './defgen',
options: {
paths: [
path.resolve(__dirname, 'common'),
],
registrar: {
function: 'registerSynchronized',
module: '@avocado/net',
},
type: 'synchronized',
},
},
},
2019-03-20 15:28:18 -05:00
{
2019-04-25 00:09:28 -05:00
test: /register-traits\.js$/,
2019-04-14 20:39:27 -05:00
use: {
2019-04-14 21:06:58 -05:00
loader: './defgen',
2019-04-14 20:39:27 -05:00
options: {
paths: [
path.resolve(__dirname, 'common'),
],
2019-04-14 21:06:58 -05:00
registrar: {
function: 'registerTrait',
2019-04-14 21:32:48 -05:00
module: '@avocado/entity',
2019-04-14 21:06:58 -05:00
},
type: 'trait',
},
2019-04-14 20:39:27 -05:00
},
2019-03-20 15:28:18 -05:00
},
2019-09-22 21:25:43 -05:00
// 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(),
},
},
],
},
2019-03-20 15:28:18 -05:00
],
},
output: {
2019-05-05 04:27:18 -05:00
// Worker happiness.
2019-04-25 00:09:28 -05:00
globalObject: `(typeof self === 'undefined' ? this : self)`,
2019-03-20 15:28:18 -05:00
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
2019-09-22 21:25:43 -05:00
plugins: [
new ExtractCssChunks({
filename: '[name].css',
}),
],
2019-03-20 15:28:18 -05:00
resolve: {
2019-04-25 00:09:28 -05:00
alias: {
2019-09-22 18:45:52 -05:00
'register-packets': path.join(__dirname, 'register-packets'),
'register-synchronizeds': path.join(__dirname, 'register-synchronizeds'),
'register-traits': path.join(__dirname, 'register-traits'),
2019-04-25 00:09:28 -05:00
},
2019-09-22 21:25:43 -05:00
modules: [
path.join(__dirname, 'node_modules'),
path.join(__dirname, 'scss'),
],
2019-03-20 15:28:18 -05:00
},
resolveLoader: {
2019-09-22 21:25:43 -05:00
modules: [
path.join(__dirname, 'node_modules'),
],
2019-03-20 15:28:18 -05:00
},
};
module.exports = config;