2017-09-14 00:01:09 +02:00
|
|
|
const Path = require('path');
|
2023-01-20 03:42:08 +01:00
|
|
|
const { JavascriptWebpackConfig, CssWebpackConfig } = require('@silverstripe/webpack-config');
|
2021-03-04 05:05:29 +01:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2017-09-14 00:01:09 +02:00
|
|
|
|
|
|
|
const ENV = process.env.NODE_ENV;
|
|
|
|
const PATHS = {
|
2019-11-11 00:18:54 +01:00
|
|
|
MODULES: 'node_modules',
|
|
|
|
ROOT: Path.resolve(),
|
|
|
|
SRC: Path.resolve('client/src'),
|
|
|
|
DIST: Path.resolve('client/dist'),
|
2021-03-04 05:05:29 +01:00
|
|
|
DIST_JS: Path.resolve('client/dist/js'),
|
2019-11-11 00:18:54 +01:00
|
|
|
LEGACY_SRC: Path.resolve('client/src/legacy'),
|
2017-09-14 00:01:09 +02:00
|
|
|
};
|
|
|
|
|
2023-01-20 03:42:08 +01:00
|
|
|
const jsConfig = new JavascriptWebpackConfig('js', PATHS, 'silverstripe/comments')
|
|
|
|
.setEntry({
|
|
|
|
CommentsInterface: `${PATHS.LEGACY_SRC}/CommentsInterface.js`,
|
|
|
|
})
|
|
|
|
.mergeConfig({
|
|
|
|
plugins: [
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: `${PATHS.MODULES}/jquery/dist/jquery.min.js`,
|
|
|
|
to: PATHS.DIST_JS
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: `${PATHS.MODULES}/jquery-validation/dist`,
|
|
|
|
from: '**/*.min.js',
|
|
|
|
to: `${PATHS.DIST_JS}/jquery-validation/`
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
})
|
|
|
|
.getConfig();
|
2021-03-04 05:05:29 +01:00
|
|
|
|
2023-01-20 03:42:08 +01:00
|
|
|
// Don't apply any externals, as this js will be used on the front-end.
|
|
|
|
jsConfig.externals = {};
|
2021-03-04 05:05:29 +01:00
|
|
|
|
2017-09-14 00:01:09 +02:00
|
|
|
const config = [
|
2023-01-20 03:42:08 +01:00
|
|
|
// Main JS bundle
|
|
|
|
jsConfig,
|
|
|
|
// sass to css
|
|
|
|
new CssWebpackConfig('css', PATHS)
|
|
|
|
.setEntry({
|
|
|
|
comments: `${PATHS.SRC}/styles/comments.scss`,
|
|
|
|
cms: `${PATHS.SRC}/styles/cms.scss`,
|
|
|
|
})
|
|
|
|
.getConfig(),
|
2017-09-14 00:01:09 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
// Use WEBPACK_CHILD=js or WEBPACK_CHILD=css env var to run a single config
|
|
|
|
module.exports = (process.env.WEBPACK_CHILD)
|
2019-11-11 00:18:54 +01:00
|
|
|
? config.find((entry) => entry.name === process.env.WEBPACK_CHILD)
|
2023-01-20 03:42:08 +01:00
|
|
|
: config;
|