silverstripe-webpack/webpack.config.common.js

127 lines
3.6 KiB
JavaScript
Raw Normal View History

2018-02-22 14:39:58 +01:00
/*
* Common Environment
*/
2018-04-21 05:36:06 +02:00
const webpack = require('webpack');
const conf = require('./webpack.configuration');
2018-02-22 14:39:58 +01:00
2018-04-21 05:36:06 +02:00
const path = require('path');
2018-02-05 12:11:01 +01:00
2018-02-21 11:19:51 +01:00
const includes = {
2018-04-21 05:36:06 +02:00
app: path.join(__dirname, conf.SRC, 'js/app.js'),
2018-02-05 12:11:01 +01:00
};
const _getAllFilesFromFolder = function(dir) {
dir = path.resolve(__dirname, dir);
2018-02-22 14:39:58 +01:00
2018-04-21 05:36:06 +02:00
const filesystem = require('fs');
2018-02-05 12:11:01 +01:00
let results = [];
2018-04-21 05:36:06 +02:00
filesystem.readdirSync(dir).forEach((file) => {
if (file === '_notes') {
return;
}
2018-02-05 12:11:01 +01:00
2018-04-21 05:36:06 +02:00
file = `${dir}/${file}`;
const stat = filesystem.statSync(file);
2018-02-05 12:11:01 +01:00
if (stat && stat.isDirectory()) {
2018-04-21 05:36:06 +02:00
results = results.concat(_getAllFilesFromFolder(file));
} else {
results.push(file);
}
2018-02-05 12:11:01 +01:00
});
return results;
};
// add page specific scripts
2018-02-22 14:39:58 +01:00
const pageScripts = _getAllFilesFromFolder(conf.TYPESJS);
2018-02-05 12:11:01 +01:00
pageScripts.forEach((file) => {
2018-04-21 05:36:06 +02:00
includes[path.basename(file, '.js')] = file;
2018-02-21 11:19:51 +01:00
});
// add page specific scss
2018-02-22 14:39:58 +01:00
const scssIncludes = _getAllFilesFromFolder(conf.TYPESSCSS);
2018-02-21 11:19:51 +01:00
scssIncludes.forEach((file) => {
2018-04-21 05:36:06 +02:00
includes[path.basename(file, '.scss')] = file;
2018-02-05 12:11:01 +01:00
});
module.exports = {
2018-02-21 11:19:51 +01:00
entry: includes,
2018-04-21 05:36:06 +02:00
devtool: 'source-map',
2018-02-05 12:11:01 +01:00
externals: {
2018-04-21 05:36:06 +02:00
'jquery': 'jQuery',
2018-02-05 12:11:01 +01:00
},
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
2018-04-21 05:36:06 +02:00
loader: 'babel-loader',
2018-02-05 12:11:01 +01:00
options: {
presets: [
2018-04-21 05:36:06 +02:00
['es2015', {
modules: false,
2018-02-05 12:11:01 +01:00
}],
2018-04-21 05:36:06 +02:00
['stage-2'],
2018-02-05 12:11:01 +01:00
],
plugins: [
2018-04-21 05:36:06 +02:00
['transform-react-jsx'],
['react-hot-loader/babel'],
],
2018-02-05 12:11:01 +01:00
},
2018-04-21 05:36:06 +02:00
},
2018-02-21 11:19:51 +01:00
}, {
test: /\.tsx?$/,
use: 'ts-loader',
2018-04-21 05:36:06 +02:00
exclude: /node_modules/,
2018-02-21 11:19:51 +01:00
}, {
test: /\.coffee?$/,
2018-04-21 05:36:06 +02:00
use: 'coffee-loader',
2018-02-05 12:11:01 +01:00
}, {
2018-04-21 05:36:06 +02:00
test: /\.(png|jpg|jpeg|gif|svg)$/,
loader: 'file-loader',
2018-02-05 12:11:01 +01:00
options: {
2018-04-21 05:36:06 +02:00
name: '[name].[ext]',
2018-02-22 14:39:58 +01:00
outputPath: 'img/',
2018-04-21 05:36:06 +02:00
publicPath: '../img/',
},
2018-02-05 12:11:01 +01:00
}, {
test: /\.worker\.js$/,
use: {
2018-04-21 05:36:06 +02:00
loader: 'worker-loader',
},
}],
2018-02-05 12:11:01 +01:00
},
2018-02-21 11:19:51 +01:00
resolve: {
2018-04-21 05:36:06 +02:00
modules: [
path.resolve(__dirname, 'public'),
'node_modules'
],
2018-02-21 11:19:51 +01:00
alias: {
'jquery': require.resolve('jquery'),
'jQuery': require.resolve('jquery'),
2018-04-21 05:36:06 +02:00
},
2018-02-21 11:19:51 +01:00
},
2018-02-05 12:11:01 +01:00
plugins: [
new webpack.ProvidePlugin({
2018-04-21 05:36:06 +02:00
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
Util: 'exports-loader?Util!bootstrap/js/dist/util',
Alert: 'exports-loader?Alert!bootstrap/js/dist/alert',
Button: 'exports-loader?Button!bootstrap/js/dist/button',
Carousel: 'exports-loader?Carousel!bootstrap/js/dist/carousel',
Collapse: 'exports-loader?Collapse!bootstrap/js/dist/collapse',
Dropdown: 'exports-loader?Dropdown!bootstrap/js/dist/dropdown',
Modal: 'exports-loader?Modal!bootstrap/js/dist/modal',
Tooltip: 'exports-loader?Tooltip!bootstrap/js/dist/tooltip',
Popover: 'exports-loader?Popover!bootstrap/js/dist/popover',
Scrollspy: 'exports-loader?Scrollspy!bootstrap/js/dist/scrollspy',
Tab: 'exports-loader?Tab!bootstrap/js/dist/tab',
}),
2018-02-05 12:11:01 +01:00
],
};