static-cms/scripts/webpack.js
Erez Rokah 6f221ab3c1 Feat: editorial workflow bitbucket gitlab (#3014)
* refactor: typescript the backends

* feat: support multiple files upload for GitLab and BitBucket

* fix: load entry media files from media folder or UI state

* chore: cleanup log message

* chore: code cleanup

* refactor: typescript the test backend

* refactor: cleanup getEntry unsued variables

* refactor: moved shared backend code to lib util

* chore: rename files to preserve history

* fix: bind readFile method to API classes

* test(e2e): switch to chrome in cypress tests

* refactor: extract common api methods

* refactor: remove most of immutable js usage from backends

* feat(backend-gitlab): initial editorial workflow support

* feat(backend-gitlab): implement missing workflow methods

* chore: fix lint error

* feat(backend-gitlab): support files deletion

* test(e2e): add gitlab cypress tests

* feat(backend-bitbucket): implement missing editorial workflow methods

* test(e2e): add BitBucket backend e2e tests

* build: update node version to 12 on netlify builds

* fix(backend-bitbucket): extract BitBucket avatar url

* test: fix git-gateway AuthenticationPage test

* test(e2e): fix some backend tests

* test(e2e): fix tests

* test(e2e): add git-gateway editorial workflow test

* chore: code cleanup

* test(e2e): revert back to electron

* test(e2e): add non editorial workflow tests

* fix(git-gateway-gitlab): don't call unpublishedEntry in simple workflow

gitlab git-gateway doesn't support editorial workflow APIs yet. This change makes sure not to call them in simple workflow

* refactor(backend-bitbucket): switch to diffstat API instead of raw diff

* chore: fix test

* test(e2e): add more git-gateway tests

* fix: post rebase typescript fixes

* test(e2e): fix tests

* fix: fix parsing of content key and add tests

* refactor: rename test file

* test(unit): add getStatues unit tests

* chore: update cypress

* docs: update beta docs
2020-01-14 17:15:14 -05:00

151 lines
4.0 KiB
JavaScript

const path = require('path');
const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const { flatMap } = require('lodash');
const { toGlobalName, externals } = require('./externals');
const pkg = require(path.join(process.cwd(), 'package.json'));
const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
const moduleNameToPath = libName => `${path.resolve(__dirname, `../node_modules/${libName}`)}/`;
const rules = () => ({
js: () => ({
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
rootMode: 'upward',
},
},
}),
css: () => [
{
test: /\.css$/,
include: ['ol', 'redux-notifications', 'react-datetime', 'codemirror'].map(moduleNameToPath),
use: ['to-string-loader', 'css-loader'],
},
],
svg: () => ({
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
exclude: [/node_modules/],
use: 'svg-inline-loader',
}),
});
const plugins = () => {
return {
ignoreEsprima: () => new webpack.IgnorePlugin(/^esprima$/, /js-yaml/),
ignoreMomentOptionalDeps: () => new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
friendlyErrors: () => new FriendlyErrorsWebpackPlugin(),
};
};
const stats = () => {
if (isProduction) {
return {
builtAt: false,
chunks: false,
colors: true,
entrypoints: false,
errorDetails: false,
hash: false,
modules: false,
timings: false,
version: false,
warnings: false,
};
}
return {
all: false,
};
};
const umdPath = path.resolve(process.cwd(), 'dist');
const umdDirPath = path.resolve(process.cwd(), 'dist/umd');
const cjsPath = path.resolve(process.cwd(), 'dist/cjs');
const targetOutputs = () => {
console.log(`Building [${pkg.name}, library: ${toGlobalName(pkg.name)}]`);
return {
umd: {
path: umdPath,
filename: `${pkg.name}.js`,
library: toGlobalName(pkg.name),
libraryTarget: 'umd',
libraryExport: toGlobalName(pkg.name),
umdNamedDefine: true,
globalObject: 'window',
},
umddir: {
path: umdDirPath,
filename: `index.js`,
library: toGlobalName(pkg.name),
libraryTarget: 'umd',
libraryExport: toGlobalName(pkg.name),
umdNamedDefine: true,
globalObject: 'window',
},
cjs: {
path: cjsPath,
filename: 'index.js',
library: toGlobalName(pkg.name),
libraryTarget: 'window',
},
};
};
const umdExternals = Object.keys(pkg.peerDependencies || {}).reduce((previous, key) => {
if (!externals[key]) throw `Missing external [${key}]`;
previous[key] = externals[key] || null;
return previous;
}, {});
/**
* Use [getConfig({ target:'umd' }), getConfig({ target:'cjs' })] for
* getting multiple configs and add the new output in targetOutputs if needed.
* Default: umd
*/
const baseConfig = ({ target = isProduction ? 'umd' : 'umddir' } = {}) => ({
context: process.cwd(),
mode: isProduction ? 'production' : 'development',
entry: './src',
output: targetOutputs()[target],
module: {
rules: flatMap(Object.values(rules()), rule => rule()),
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
plugins: Object.values(plugins()).map(plugin => plugin()),
devtool: isTest ? '' : 'source-map',
target: 'web',
/**
* Exclude peer dependencies from package bundles.
*/
externals:
target.substr(0, 3) === 'umd'
? umdExternals
: (context, request, cb) => {
const externals = Object.keys(pkg.peerDependencies || {});
const isPeerDep = dep => new RegExp(`^${dep}($|/)`).test(request);
return externals.some(isPeerDep) ? cb(null, request) : cb();
},
stats: stats(),
});
const getConfig = ({ baseOnly = false } = {}) => {
if (baseOnly) {
// netlify-cms build
return baseConfig({ target: 'umd' });
}
return [baseConfig({ target: 'umd' })];
};
module.exports = {
getConfig,
rules: rules(),
plugins: plugins(),
};