mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
cleaned up plugins in webpack
This commit is contained in:
+7
-3
@@ -10,6 +10,7 @@ const PLUGINS_JSON = process.env.TALK_PLUGINS_JSON;
|
||||
// Add the current path to the module root.
|
||||
amp.addPath(__dirname);
|
||||
|
||||
let pluginsPath;
|
||||
let plugins = {};
|
||||
|
||||
// Try to parse the plugins.json file, logging out an error if the plugins.json
|
||||
@@ -22,14 +23,16 @@ try {
|
||||
|
||||
if (PLUGINS_JSON && PLUGINS_JSON.length > 0) {
|
||||
debug('Now using TALK_PLUGINS_JSON environment variable for plugins');
|
||||
plugins = require(envPlugins);
|
||||
pluginsPath = envPlugins;
|
||||
} else if (fs.existsSync(customPlugins)) {
|
||||
debug(`Now using ${customPlugins} for plugins`);
|
||||
plugins = JSON.parse(fs.readFileSync(customPlugins, 'utf8'));
|
||||
pluginsPath = customPlugins;
|
||||
} else {
|
||||
debug(`Now using ${defaultPlugins} for plugins`);
|
||||
plugins = JSON.parse(fs.readFileSync(defaultPlugins, 'utf8'));
|
||||
pluginsPath = defaultPlugins;
|
||||
}
|
||||
|
||||
plugins = require(pluginsPath);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
console.error('plugins.json and plugins.default.json not found, plugins will not be active');
|
||||
@@ -249,6 +252,7 @@ class PluginManager {
|
||||
|
||||
module.exports = {
|
||||
plugins,
|
||||
pluginsPath,
|
||||
PluginManager,
|
||||
isInternal,
|
||||
pluginPath,
|
||||
|
||||
+6
-22
@@ -1,5 +1,4 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const CompressionPlugin = require('compression-webpack-plugin');
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const precss = require('precss');
|
||||
@@ -10,26 +9,11 @@ const webpack = require('webpack');
|
||||
// Possibly load the config from the .env file (if there is one).
|
||||
require('dotenv').config();
|
||||
|
||||
const {plugins, PluginManager} = require('./plugins');
|
||||
const {plugins, pluginsPath, PluginManager} = require('./plugins');
|
||||
const manager = new PluginManager(plugins);
|
||||
const targetPlugins = manager.section('targets').plugins;
|
||||
|
||||
const pluginManager = new PluginManager(plugins);
|
||||
const targetPlugins = pluginManager.section('targets').plugins;
|
||||
|
||||
let pluginsConfigPath;
|
||||
|
||||
let envPlugins = path.join(__dirname, 'plugins.env.js');
|
||||
let customPlugins = path.join(__dirname, 'plugins.json');
|
||||
let defaultPlugins = path.join(__dirname, 'plugins.default.json');
|
||||
|
||||
if (process.env.TALK_PLUGINS_JSON && process.env.TALK_PLUGINS_JSON.length > 0) {
|
||||
pluginsConfigPath = envPlugins;
|
||||
} else if (fs.existsSync(customPlugins)) {
|
||||
pluginsConfigPath = customPlugins;
|
||||
} else {
|
||||
pluginsConfigPath = defaultPlugins;
|
||||
}
|
||||
|
||||
console.log(`Using ${pluginsConfigPath} as the plugin configuration path`);
|
||||
console.log(`Using ${pluginsPath} as the plugin configuration path`);
|
||||
|
||||
// Edit the build targets and embeds below.
|
||||
|
||||
@@ -89,7 +73,7 @@ const config = {
|
||||
{
|
||||
loader: 'plugins-loader',
|
||||
test: /\.(json|js)$/,
|
||||
include: pluginsConfigPath
|
||||
include: pluginsPath
|
||||
},
|
||||
{
|
||||
loader: 'babel-loader',
|
||||
@@ -168,7 +152,7 @@ const config = {
|
||||
resolve: {
|
||||
alias: {
|
||||
plugins: path.resolve(__dirname, 'plugins/'),
|
||||
pluginsConfig: pluginsConfigPath
|
||||
pluginsConfig: pluginsPath
|
||||
},
|
||||
modules: [
|
||||
path.resolve(__dirname, 'plugins'),
|
||||
|
||||
Reference in New Issue
Block a user