Lexiconga/webpack.config.js

140 lines
3.0 KiB
JavaScript

// Set BUILDMODE to:
// 'production' to reduce overhead.
// 'donotsave' to clear the dictionary details and database on each load.
// 'emptydetails' to clear the dictionary details on each load.
// 'emptydb' to clear the database on each load.
// 'development' to not do anything special.
const BUILDMODE = 'development';
const webpack = require('webpack');
const path = require('path');
const BUILD_DIR = path.resolve(__dirname, 'public');
const APP_DIR = path.resolve(__dirname, 'src');
const webpackConfig = {
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'lexiconga.js',
},
module: {
rules: [
{
test: (/\.scss$/),
exclude: (/node_modules/),
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer'),
],
},
},
{
loader: 'sass-loader',
options: {
file: './src/sass/styles.scss',
outFile: './public/styles.css',
outputStyle: 'compressed',
},
},
],
},
{
test: (/\.html$/),
exclude: (/node_modules/),
use: [
'html-loader',
],
},
{
test: (/\.(txt|md)$/),
exclude: (/node_modules/),
use: [
'raw-loader'
],
},
{
test: (/\.jsx?$/),
exclude: (/node_modules/),
use: [
{
loader: 'babel-loader',
options: {
presets: [
'env',
],
plugins: [
'inferno',
],
},
}
],
},
{
test: (/\.(png|woff|woff2|eot|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/),
use: [
{
loader: 'url-loader',
options: {
limit: 100000,
mimetype: 'application/font-woff',
name: './assets/fonts/[name].[ext]',
}
}
]
}
]
},
resolve: {
extensions: [
'.js',
'.jsx',
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(BUILDMODE),
},
MARKDOWN_LINK: JSON.stringify('https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet'),
}),
],
devServer: {
contentBase: path.join(__dirname, "public"),
compress: true,
port: 3013,
},
};
if (BUILDMODE === 'production') {
webpackConfig.plugins.push(
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false,
},
})
);
webpackConfig.devtool = 'hidden-source-map';
} else {
webpackConfig.devtool = 'source-map';
}
module.exports = webpackConfig;