fix: flecks build pattern

This commit is contained in:
cha0s 2023-12-01 19:56:10 -06:00
parent 572832b037
commit cf2b787a9f
2 changed files with 48 additions and 46 deletions

View File

@ -5,18 +5,23 @@ const {
join,
} = require('path');
const babelmerge = require('babel-merge');
const CopyPlugin = require('copy-webpack-plugin');
const glob = require('glob');
const ESLintPlugin = require('eslint-webpack-plugin');
const D = require('../../debug');
const R = require('../../require');
const {defaultConfig, externals} = require('../webpack');
const {defaultConfig, externals, regexFromExtensions} = require('../webpack');
const eslintConfigFn = require('./default.eslint.config');
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/core/server/build/fleck.webpack.config.js');
const debugSilly = debug.extend('silly');
const source = join(FLECKS_CORE_ROOT, 'src');
const tests = join(FLECKS_CORE_ROOT, 'test');
@ -97,6 +102,48 @@ module.exports = (env, argv, flecks) => {
},
target: 'node',
});
const merging = [
{
plugins: ['@babel/plugin-syntax-dynamic-import'],
presets: [
[
'@babel/preset-env',
{
shippedProposals: true,
targets: {
esmodules: true,
node: 'current',
},
},
],
],
},
];
if (flecks) {
merging.push({configFile: flecks.buildConfig('babel.config.js')});
const rcBabel = flecks.babel();
debugSilly('.flecksrc: babel: %j', rcBabel);
merging.push(...rcBabel.map(([, babel]) => babel));
}
const babelConfig = babelmerge.all(merging);
const extensionsRegex = regexFromExtensions(config.resolve.extensions);
config.module.rules.push(
{
include: [source, tests],
test: extensionsRegex,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
configFile: false,
...babelConfig,
},
},
],
},
);
const eslint = eslintConfigFn(flecks);
eslint.settings['import/resolver'].webpack = {
config: {

View File

@ -1,22 +1,14 @@
const {chmod} = require('fs');
const {join} = require('path');
const babelmerge = require('babel-merge');
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const D = require('../debug');
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
const debug = D('@flecks/core/server/webpack');
const debugSilly = debug.extend('silly');
const source = join(FLECKS_CORE_ROOT, 'src');
const tests = join(FLECKS_CORE_ROOT, 'test');
exports.banner = (options) => (
new webpack.BannerPlugin({
entryOnly: true,
@ -29,31 +21,9 @@ exports.copy = (options) => (new CopyPlugin(options));
exports.defaultConfig = (flecks, specializedConfig) => {
const extensions = ['.mjs', '.js', '.json', '.wasm'];
const merging = [
{
plugins: ['@babel/plugin-syntax-dynamic-import'],
presets: [
[
'@babel/preset-env',
{
shippedProposals: true,
targets: {
esmodules: true,
node: 'current',
},
},
],
],
},
];
if (flecks) {
extensions.push(...flecks.exts());
merging.push({configFile: flecks.buildConfig('babel.config.js')});
const rcBabel = flecks.babel();
debugSilly('.flecksrc: babel: %j', rcBabel);
merging.push(...rcBabel.map(([, babel]) => babel));
}
const babelConfig = babelmerge.all(merging);
const extensionsRegex = exports.regexFromExtensions(extensions);
const defaults = {
context: FLECKS_CORE_ROOT,
@ -66,21 +36,6 @@ exports.defaultConfig = (flecks, specializedConfig) => {
test: extensionsRegex,
use: ['source-map-loader'],
},
{
include: [source, tests],
test: extensionsRegex,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
configFile: false,
...babelConfig,
},
},
],
},
],
},
output: {