fix: babel opts

This commit is contained in:
cha0s 2020-12-17 02:08:16 -06:00
parent f5a8f70bfe
commit 931596d0a4
4 changed files with 15 additions and 6 deletions

View File

@ -13,7 +13,7 @@ module.exports[0].use.push(copy({
patterns: ['index.js', 'index.ejs', 'latus.js'].map((path) => ({
from: `src/client/${path}`,
to: 'client',
})).concat(['.neutrinorc.js', 'plugins.js', 'webpack.config.js'].map((path) => ({
})).concat(['.neutrinorc.js', 'client-plugins.js', 'webpack.config.js'].map((path) => ({
from: `src/build/${path}`,
to: 'build',
}))),

View File

@ -8,7 +8,7 @@ const {DefinePlugin, EnvironmentPlugin} = require('webpack');
const {Latus} = require('@latus/core');
const VirtualModulesPlugin = require('webpack-virtual-modules');
const plugins = require('./plugins');
const clientPlugins = require('./client-plugins');
const latus = Latus.create();
@ -66,12 +66,21 @@ const client = {
apply(compiler) {
const plugin = new VirtualModulesPlugin();
plugin.apply(compiler);
let babelOptions;
neutrino.config.module
.rule('compile')
.use('babel')
.tap(options => {
babelOptions = options;
});
const {plugins, presets, ...rest} = babelOptions;
// eslint-disable-next-line no-eval
eval('require')('@babel/register')({
presets: ['@babel/preset-react'],
plugins,
presets,
});
compiler.hooks.beforeCompile.tapPromise('LatusPlugin', async () => {
const paths = Object.keys(await plugins(this.latus))
const paths = Object.keys(await clientPlugins(this.latus))
.map((path) => Latus.runtimePath(path));
plugin.writeModule('node_modules/@latus/core/virtual', [
'/* eslint-disable global-require, no-undef */',

View File

@ -1,4 +1,4 @@
import plugins from './build/plugins';
import clientPlugins from './build/client-plugins';
export default (latus) => async (req, res, next) => {
if ('/latus.config.js' !== req.path) {
@ -6,6 +6,6 @@ export default (latus) => async (req, res, next) => {
return;
}
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
const codedConfig = encodeURIComponent(JSON.stringify(await plugins(latus, req)));
const codedConfig = encodeURIComponent(JSON.stringify(await clientPlugins(latus, req)));
res.send(`window.$$latusConfig = JSON.parse(decodeURIComponent("${codedConfig}"));`);
};