mirror of
https://github.com/wassname/talk.git
synced 2026-08-15 12:55:10 +08:00
Adjusted loaders, webpack
This commit is contained in:
@@ -10,22 +10,24 @@
|
||||
const {stripIndent} = require('common-tags');
|
||||
|
||||
function getPluginList(config) {
|
||||
return config.client.map(x => typeof x === 'string' ? x : Object.keys(x)[0]);
|
||||
if (config && config.client) {
|
||||
return config.client.map(x => typeof x === 'string' ? x : Object.keys(x)[0]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
module.exports = function(source) {
|
||||
this.cacheable();
|
||||
const config = this.exec(source, this.resourcePath);
|
||||
const plugins = getPluginList(config);
|
||||
|
||||
const list = [];
|
||||
plugins.forEach(plugin => {
|
||||
list.push(`{module: require('plugins/${plugin}/client/index.js'), plugin: '${plugin}'}`);
|
||||
});
|
||||
const plugins = getPluginList(config).map((plugin) => `{
|
||||
module: require('${plugin}/client'),
|
||||
plugin: '${plugin}'
|
||||
}`);
|
||||
|
||||
return stripIndent`
|
||||
module.exports = [
|
||||
${list.join(',')}
|
||||
${plugins.join(',')}
|
||||
];
|
||||
`;
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = JSON.parse(process.env.TALK_PLUGINS_JSON);
|
||||
+4
-4
@@ -13,13 +13,13 @@ let plugins = {};
|
||||
// file isn't loaded, but continuing. Else, like a parsing error, throw it and
|
||||
// crash the program.
|
||||
try {
|
||||
let defaultPlugins = path.join(__dirname, 'plugins.default.json');
|
||||
let envPlugins = path.join(__dirname, 'plugins.env.js');
|
||||
let customPlugins = path.join(__dirname, 'plugins.json');
|
||||
let envPluginJSON = process.env.TALK_PLUGINS_JSON;
|
||||
let defaultPlugins = path.join(__dirname, 'plugins.default.json');
|
||||
|
||||
if (envPluginJSON && envPluginJSON.length > 0) {
|
||||
if (process.env.TALK_PLUGINS_JSON && process.env.TALK_PLUGINS_JSON.length > 0) {
|
||||
debug('Now using TALK_PLUGINS_JSON environment variable for plugins');
|
||||
plugins = JSON.parse(envPluginJSON);
|
||||
plugins = require(envPlugins);
|
||||
} else if (fs.existsSync(customPlugins)) {
|
||||
debug(`Now using ${customPlugins} for plugins`);
|
||||
plugins = JSON.parse(fs.readFileSync(customPlugins, 'utf8'));
|
||||
|
||||
+31
-7
@@ -1,10 +1,30 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const precss = require('precss');
|
||||
const Copy = require('copy-webpack-plugin');
|
||||
const LicenseWebpackPlugin = require('license-webpack-plugin');
|
||||
const webpack = require('webpack');
|
||||
|
||||
// Possibly load the config from the .env file (if there is one).
|
||||
require('dotenv').config();
|
||||
|
||||
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`);
|
||||
|
||||
// Edit the build targets and embeds below.
|
||||
|
||||
const buildTargets = [
|
||||
@@ -53,6 +73,11 @@ module.exports = {
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
loader: 'plugins-loader',
|
||||
test: /\.(json|js)$/,
|
||||
include: pluginsConfigPath
|
||||
},
|
||||
{
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/,
|
||||
@@ -61,11 +86,6 @@ module.exports = {
|
||||
cacheDirectory: true
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'plugins-loader',
|
||||
test: /\.json$/,
|
||||
include: path.join(__dirname, 'plugins.json')
|
||||
},
|
||||
{
|
||||
loader: 'json-loader',
|
||||
test: /\.json$/,
|
||||
@@ -120,8 +140,11 @@ module.exports = {
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
'VERSION': `"${require('./package.json').version}"`
|
||||
'VERSION': `"${require('./package.json').version}"`,
|
||||
}
|
||||
}),
|
||||
new webpack.EnvironmentPlugin({
|
||||
'TALK_PLUGINS_JSON': '{}'
|
||||
})
|
||||
],
|
||||
resolveLoader: {
|
||||
@@ -130,9 +153,10 @@ module.exports = {
|
||||
resolve: {
|
||||
alias: {
|
||||
plugins: path.resolve(__dirname, 'plugins/'),
|
||||
pluginsConfig: path.resolve(__dirname, 'plugins.json')
|
||||
pluginsConfig: pluginsConfigPath
|
||||
},
|
||||
modules: [
|
||||
path.resolve(__dirname, 'plugins'),
|
||||
path.resolve(__dirname, 'client'),
|
||||
...buildTargets.map(target => path.join(__dirname, 'client', target, 'src')),
|
||||
...buildEmbeds.map(embed => path.join(__dirname, 'client', `coral-embed-${embed}`, 'src')),
|
||||
|
||||
Reference in New Issue
Block a user