silverstripe-webpack/webpack.config.common.js

118 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-02-22 14:39:58 +01:00
/*
* Common Environment
*/
2018-02-05 12:11:01 +01:00
const webpack = require("webpack");
const conf = require("./webpack.configuration");
2018-02-22 14:39:58 +01:00
const path = require("path");
2018-02-05 12:11:01 +01:00
2018-02-21 11:19:51 +01:00
const includes = {
2018-02-22 14:39:58 +01:00
app: path.join(__dirname, conf.SRC, "js/app.js"),
2018-02-05 12:11:01 +01:00
};
const _getAllFilesFromFolder = function(dir) {
2018-02-22 14:39:58 +01:00
dir = path.join(__dirname, dir);
2018-02-05 12:11:01 +01:00
let filesystem = require("fs");
let results = [];
filesystem.readdirSync(dir).forEach(function(file) {
file = dir + "/" + file;
let stat = filesystem.statSync(file);
if (stat && stat.isDirectory()) {
results = results.concat(_getAllFilesFromFolder(file))
} else results.push(file);
});
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-02-21 11:19:51 +01:00
includes[path.basename(file, ".js")] = file;
});
// 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) => {
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-02-05 12:11:01 +01:00
devtool: "source-map",
externals: {
2018-02-08 11:55:22 +01:00
"jquery": "jQuery",
2018-02-05 12:11:01 +01:00
},
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
["es2015", {
modules: false
}],
["stage-2"]
],
plugins: [
["transform-react-jsx"],
["react-hot-loader/babel"],
]
},
}
2018-02-21 11:19:51 +01:00
}, {
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}, {
test: /\.coffee?$/,
use: 'coffee-loader'
2018-02-05 12:11:01 +01:00
}, {
test: /\.(png|jpg|gif|svg)$/,
loader: "file-loader",
options: {
2018-02-22 14:39:58 +01:00
name: "[name].[ext]",
outputPath: 'img/',
publicPath: '/site/dist/img/'
2018-02-05 12:11:01 +01:00
}
}, {
test: /\.worker\.js$/,
use: {
loader: "worker-loader"
}
}]
},
2018-02-21 11:19:51 +01:00
resolve: {
alias: {
'jquery': require.resolve('jquery'),
'jQuery': require.resolve('jquery'),
}
},
2018-02-05 12:11:01 +01:00
plugins: [
new webpack.ProvidePlugin({
$: "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",
})
],
};