2018-03-25 18:03:08 +00:00
|
|
|
// AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
const path = require ('path')
|
|
|
|
const WebpackSweetEntry = require('webpack-sweet-entry');
|
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
|
|
const StringReplacePlugin = require("string-replace-webpack-plugin");
|
|
|
|
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
2018-05-21 20:03:46 +00:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const CompressionPlugin = require("compression-webpack-plugin");
|
2018-05-24 15:06:44 +00:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
const config_button=require('./config/settings.json');
|
|
|
|
|
|
|
|
const sourcePath = path.join(__dirname, 'client');
|
|
|
|
const buildPath = path.join(__dirname, 'public/client');
|
|
|
|
const translationPath = path.join(__dirname, 'public/javascripts/_final.js')
|
2018-03-29 20:25:03 +00:00
|
|
|
const reactEntrySourcePath = path.join(__dirname, 'javascripts')
|
|
|
|
const reactEntryOutputPath = path.join(__dirname, 'public')
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2018-05-24 15:06:44 +00:00
|
|
|
|
2018-05-21 20:03:46 +00:00
|
|
|
let inProduction = process.env.NODE_ENV === 'production'
|
|
|
|
|
|
|
|
let devToProdLibraries = {
|
|
|
|
react:{
|
|
|
|
debug: "node_modules/react/umd/react.development.js",
|
|
|
|
production: "node_modules/react/umd/react.production.min.js"
|
|
|
|
},
|
|
|
|
reactDom: {
|
|
|
|
debug: "node_modules/react-dom/umd/react-dom.development.js",
|
|
|
|
production: "node_modules/react-dom/umd/react-dom.production.min.js"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let common_rules= [
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
// configure replacements for file patterns
|
|
|
|
{
|
|
|
|
test: /donate-button.v2.js$/,
|
|
|
|
loader: [
|
|
|
|
{loader: 'string-replace-loader',
|
|
|
|
options: {
|
|
|
|
search: 'REPLACE_FULL_HOST',
|
|
|
|
replace: config_button.button.url,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'string-replace-loader',
|
|
|
|
options: {
|
|
|
|
search: 'REPLACE_CSS_URL',
|
|
|
|
replace: config_button.button.css,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"babel-loader"]
|
|
|
|
},
|
2018-03-29 20:25:03 +00:00
|
|
|
{ test: /\.tsx?$/, loader:"ts-loader"},
|
2018-03-25 17:30:42 +00:00
|
|
|
{ test: /\.js$/, exclude: /node_modules|froala/, loader: "babel-loader" },
|
|
|
|
{ test: /\.es6$/, exclude: /node_modules/, loader: "babel-loader" }
|
|
|
|
]
|
2018-05-21 20:03:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
let targets = {
|
2018-03-25 17:30:42 +00:00
|
|
|
base: {
|
|
|
|
module:{
|
|
|
|
rules: common_rules
|
|
|
|
},
|
|
|
|
entry: WebpackSweetEntry(path.resolve(sourcePath, 'js/**/page.js'), 'js', 'js'),
|
|
|
|
output: {
|
|
|
|
path: path.resolve(buildPath, 'js'),
|
|
|
|
filename: '[name].js'
|
|
|
|
},
|
|
|
|
plugins: [
|
2018-03-29 20:25:03 +00:00
|
|
|
new CleanWebpackPlugin([path.resolve(buildPath, 'js')])
|
|
|
|
]
|
2018-03-25 17:30:42 +00:00
|
|
|
}
|
|
|
|
,
|
|
|
|
button: {
|
|
|
|
module:{
|
|
|
|
rules: common_rules
|
|
|
|
},
|
|
|
|
entry: path.resolve(sourcePath, 'js/widget/donate-button.v2.js'),
|
|
|
|
output: {
|
|
|
|
path: path.resolve(path.join(__dirname, 'public', 'js')),
|
|
|
|
filename: 'donate-button.v2.js'
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
// an instance of the plugin must be present
|
|
|
|
new StringReplacePlugin()
|
|
|
|
]
|
|
|
|
},
|
|
|
|
translations: {
|
|
|
|
module:{
|
|
|
|
rules: common_rules
|
|
|
|
},
|
|
|
|
entry: translationPath,
|
|
|
|
output: {
|
|
|
|
path: path.join(buildPath, 'js'),
|
|
|
|
filename: 'i18n.js'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {import: true, importLoaders: 1}
|
|
|
|
}
|
|
|
|
, 'postcss-loader']
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
entry: path.resolve(sourcePath, 'css/global/page.css'),
|
|
|
|
output: {
|
|
|
|
path: path.resolve(buildPath, 'css/global'),
|
|
|
|
filename: 'page.css'
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new ExtractTextPlugin('page.css'),
|
|
|
|
new CleanWebpackPlugin([path.resolve(buildPath, 'css')])
|
|
|
|
]
|
2018-03-29 20:25:03 +00:00
|
|
|
},
|
2018-05-21 20:03:46 +00:00
|
|
|
bootstrap: {
|
|
|
|
entry: ['bootstrap-loader'],
|
|
|
|
output: {
|
|
|
|
path: path.resolve(buildPath, 'css'),
|
|
|
|
filename: 'bootstrap.css'
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new ExtractTextPlugin('bootstrap.css')
|
|
|
|
]
|
|
|
|
},
|
2018-05-24 15:06:44 +00:00
|
|
|
loading_indicator: {
|
|
|
|
module:{
|
|
|
|
rules: common_rules
|
|
|
|
},
|
|
|
|
entry: path.resolve(reactEntrySourcePath, "app", "loading_indicator.ts"),
|
|
|
|
output: {
|
|
|
|
path: path.resolve(reactEntryOutputPath, 'app'),
|
|
|
|
filename: 'loading_indicator.js'
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
2018-03-29 20:25:03 +00:00
|
|
|
react: {
|
|
|
|
module:{
|
|
|
|
rules: common_rules
|
|
|
|
},
|
2018-05-21 20:03:46 +00:00
|
|
|
entry: WebpackSweetEntry(path.resolve(reactEntrySourcePath, "app/*.tsx"), 'ts', 'app'),
|
2018-03-29 20:25:03 +00:00
|
|
|
output: {
|
|
|
|
path: path.resolve(reactEntryOutputPath, 'app'),
|
|
|
|
filename: '[name].js'
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: [".ts", ".tsx", ".js", ".json"],
|
|
|
|
},
|
|
|
|
plugins: [
|
2018-05-21 20:03:46 +00:00
|
|
|
new CleanWebpackPlugin([path.resolve(reactEntryOutputPath, 'app')]),
|
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
name: 'vendor',
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin([{from: inProduction ? devToProdLibraries.react.production : devToProdLibraries.react.debug, to: path.resolve('public', 'app', 'react.js')}]),
|
|
|
|
new CopyWebpackPlugin([{from: inProduction ? devToProdLibraries.reactDom.production : devToProdLibraries.reactDom.debug, to:path.resolve('public', 'app', 'react-dom.js')}])
|
|
|
|
|
|
|
|
],
|
|
|
|
externals: {
|
|
|
|
'react': 'React',
|
|
|
|
'react-dom': 'ReactDOM',
|
|
|
|
'i18n': 'I18n'
|
|
|
|
}
|
2018-03-25 17:30:42 +00:00
|
|
|
}
|
2018-03-25 18:03:08 +00:00
|
|
|
}
|
2018-05-21 20:03:46 +00:00
|
|
|
|
|
|
|
let mergeToTargets = {
|
|
|
|
devtool: 'inline-source-map',
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inProduction)
|
|
|
|
mergeToTargets = {
|
|
|
|
plugins: [
|
2018-05-24 15:06:44 +00:00
|
|
|
new UglifyJsPlugin(),
|
2018-05-21 20:03:46 +00:00
|
|
|
new CompressionPlugin({
|
|
|
|
asset: '[path].gz'
|
|
|
|
})
|
|
|
|
]}
|
|
|
|
let output = []
|
|
|
|
for(let name in targets){
|
|
|
|
output.push(merge(targets[name], mergeToTargets));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = output
|