2017-09-14 00:01:09 +02:00
|
|
|
const Path = require('path');
|
2021-03-04 05:05:29 +01:00
|
|
|
const dir = require('node-dir');
|
2017-09-14 00:01:09 +02:00
|
|
|
const webpackConfig = 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 {
|
|
|
|
resolveJS,
|
|
|
|
externalJS,
|
|
|
|
moduleJS,
|
|
|
|
pluginJS,
|
|
|
|
moduleCSS,
|
|
|
|
pluginCSS,
|
|
|
|
} = webpackConfig;
|
|
|
|
|
|
|
|
const ENV = process.env.NODE_ENV;
|
|
|
|
const PATHS = {
|
2019-11-11 00:18:54 +01:00
|
|
|
MODULES: 'node_modules',
|
2021-03-04 05:05:29 +01:00
|
|
|
MODULES_ABS: Path.resolve('node_modules'),
|
2019-11-11 00:18:54 +01:00
|
|
|
FILES_PATH: '../',
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-03-04 05:05:29 +01:00
|
|
|
const copyData = [
|
|
|
|
{
|
|
|
|
from: PATHS.MODULES + '/jquery/dist/jquery.min.js',
|
|
|
|
to: PATHS.DIST_JS
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a list of files matching the `*.min.js` pattern to copy from a source
|
|
|
|
* directory to a dist directory.
|
|
|
|
*/
|
|
|
|
const addMinFiles = (from, to) => {
|
|
|
|
const sourceDir = PATHS.MODULES_ABS + from;
|
|
|
|
dir.files(sourceDir, (err, files) => {
|
|
|
|
if (err) throw err;
|
|
|
|
files.forEach(file => {
|
|
|
|
filename = file.replace(sourceDir, '');
|
|
|
|
if (!filename.match(/\.min\.js$/)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
copyData.push({
|
|
|
|
from: PATHS.MODULES + from + filename,
|
|
|
|
to: PATHS.DIST_JS + to + filename
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
addMinFiles('/jquery-validation/dist', '/jquery-validation');
|
|
|
|
|
2017-09-14 00:01:09 +02:00
|
|
|
const config = [
|
2019-11-11 00:18:54 +01:00
|
|
|
{
|
|
|
|
name: 'js',
|
|
|
|
entry: {
|
|
|
|
CommentsInterface: `${PATHS.LEGACY_SRC}/CommentsInterface.js`,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: PATHS.DIST,
|
|
|
|
filename: 'js/[name].js',
|
|
|
|
},
|
|
|
|
devtool: (ENV !== 'production') ? 'source-map' : '',
|
|
|
|
resolve: resolveJS(ENV, PATHS),
|
|
|
|
externals: externalJS(ENV, PATHS),
|
|
|
|
module: moduleJS(ENV, PATHS),
|
2021-03-04 05:05:29 +01:00
|
|
|
plugins: pluginJS(ENV, PATHS).concat([
|
|
|
|
new CopyWebpackPlugin(copyData)
|
|
|
|
])
|
2017-09-14 00:01:09 +02:00
|
|
|
},
|
2019-11-11 00:18:54 +01:00
|
|
|
{
|
|
|
|
name: 'css',
|
|
|
|
entry: {
|
|
|
|
comments: `${PATHS.SRC}/styles/comments.scss`,
|
|
|
|
cms: `${PATHS.SRC}/styles/cms.scss`,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: PATHS.DIST,
|
|
|
|
filename: 'styles/[name].css',
|
|
|
|
},
|
|
|
|
devtool: (ENV !== 'production') ? 'source-map' : '',
|
|
|
|
module: moduleCSS(ENV, PATHS),
|
|
|
|
plugins: pluginCSS(ENV, PATHS),
|
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)
|
|
|
|
: module.exports = config;
|