static-cms/webpack.config.js

89 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-07-17 19:13:52 -04:00
const fs = require('fs');
const path = require('path');
2018-07-23 12:30:15 -04:00
const webpack = require('webpack');
2018-07-17 19:13:52 -04:00
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const pkg = require(path.join(process.cwd(), 'package.json'));
2018-07-23 12:30:15 -04:00
const isProduction = process.env.NODE_ENV === 'production';
const plugins = () => {
const defaultPlugins = [
new FriendlyErrorsWebpackPlugin(),
];
if (isProduction) {
return [
...defaultPlugins,
new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
moduleFilenameTemplate: info => path.posix.normalize(`../src/${info.resourcePath}`),
noSources: true,
}),
];
}
return [
...defaultPlugins,
];
};
const stats = () => {
if (isProduction) {
return {
builtAt: false,
colors: true,
entrypoints: false,
hash: false,
modules: false,
timings: false,
version: false,
};
}
return {
all: false,
};
};
2018-07-17 19:13:52 -04:00
module.exports = {
2018-07-23 12:30:15 -04:00
mode: isProduction ? 'production' : 'development',
2018-07-17 19:13:52 -04:00
entry: './src/index.js',
output: {
path: process.cwd(),
filename: pkg.main,
library: pkg.name,
libraryTarget: 'umd',
umdNamedDefine: true,
},
module: {
rules: [
{
test: /\.js$/,
2018-07-23 12:30:15 -04:00
use: {
loader: 'babel-loader',
options: {
configFile: path.join(__dirname, 'babel.config.js'),
},
},
2018-07-17 19:13:52 -04:00
exclude: /node_modules/,
},
2018-07-23 12:30:15 -04:00
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
exclude: [/node_modules/],
loader: 'svg-inline-loader',
},
2018-07-17 19:13:52 -04:00
],
},
2018-07-23 12:30:15 -04:00
plugins: plugins(),
devtool: !isProduction && 'source-map',
2018-07-17 19:13:52 -04:00
target: 'web',
2018-07-23 12:30:15 -04:00
/**
* Exclude peer dependencies from package bundles.
*/
2018-07-17 19:13:52 -04:00
externals: (context, request, cb) => {
const peerDeps = Object.keys(pkg.peerDependencies || {});
2018-07-23 12:14:53 -04:00
const isPeerDep = dep => new RegExp(`^${dep}($|/)`).test(request);
2018-07-17 19:13:52 -04:00
return peerDeps.some(isPeerDep) ? cb(null, request) : cb();
},
2018-07-23 12:30:15 -04:00
stats: stats(),
2018-07-17 19:13:52 -04:00
};