2018-09-26 21:16:35 -04:00
|
|
|
const path = require('path');
|
|
|
|
|
2018-09-27 15:44:30 -04:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2018-10-18 22:03:56 -04:00
|
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
2018-12-12 12:05:19 -05:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
const isProduction = (process.env.NODE_ENV === 'production');
|
|
|
|
|
|
|
|
console.log(`Renderer module building in production mode? ${isProduction}`);
|
2018-10-18 22:03:56 -04:00
|
|
|
|
|
|
|
const babelOptions = {
|
|
|
|
// Explicitly disable babelrc so we don't catch various config
|
|
|
|
// in much lower dependencies.
|
|
|
|
babelrc: false,
|
|
|
|
plugins: [
|
2018-10-19 20:45:45 -04:00
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
'@babel/plugin-transform-async-to-generator',
|
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
2018-10-18 22:03:56 -04:00
|
|
|
['react-intl', {
|
|
|
|
messagesDir: './translations/messages/'
|
|
|
|
}]
|
|
|
|
],
|
|
|
|
presets: [
|
2018-10-19 20:45:45 -04:00
|
|
|
['@babel/preset-env', {targets: {electron: '3.0.2'}}],
|
|
|
|
'@babel/preset-react'
|
2018-10-18 22:03:56 -04:00
|
|
|
]
|
|
|
|
};
|
2018-09-27 15:44:30 -04:00
|
|
|
|
2018-09-26 21:16:35 -04:00
|
|
|
module.exports = {
|
2018-12-12 12:05:19 -05:00
|
|
|
mode: isProduction ? 'production' : 'development',
|
2018-09-26 21:16:35 -04:00
|
|
|
module: {
|
|
|
|
rules: [
|
2018-10-18 22:03:56 -04:00
|
|
|
// Override the *.js defaults from electron-webpack
|
|
|
|
// The test/include/exclude must match the defaults exactly for webpack-merge to do the override
|
2018-09-26 21:16:35 -04:00
|
|
|
{
|
2018-10-18 22:03:56 -04:00
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /(node_modules|bower_components)/,
|
2018-09-26 21:16:35 -04:00
|
|
|
loader: 'babel-loader',
|
2018-10-18 22:03:56 -04:00
|
|
|
options: babelOptions
|
|
|
|
},
|
|
|
|
// Add a new rule for the other files we want to run through babel
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
2018-09-27 15:13:26 -04:00
|
|
|
include: [
|
|
|
|
path.resolve(__dirname, 'src', 'renderer'),
|
|
|
|
/node_modules[\\/]scratch-[^\\/]+[\\/]src/
|
|
|
|
],
|
2018-10-18 22:03:56 -04:00
|
|
|
loader: 'babel-loader',
|
|
|
|
options: babelOptions
|
2018-12-12 12:05:19 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /.jsx?$/,
|
|
|
|
loader: 'source-map-loader',
|
|
|
|
enforce: 'pre'
|
2018-09-26 21:16:35 -04:00
|
|
|
}
|
|
|
|
]
|
2018-09-27 15:44:30 -04:00
|
|
|
},
|
2018-10-13 04:09:45 -04:00
|
|
|
optimization: {
|
2018-10-18 22:03:56 -04:00
|
|
|
// Use `--env.minify=false` to disable the UglifyJsPlugin instance automatically injected by electron-webpack.
|
|
|
|
// Otherwise it will do double-duty with this one.
|
2018-12-21 14:27:35 -05:00
|
|
|
minimizer: [
|
|
|
|
new UglifyJsPlugin({
|
|
|
|
cache: true,
|
|
|
|
parallel: true,
|
|
|
|
sourceMap: true, // disable this if UglifyJSPlugin takes too long and/or runs out of memory
|
|
|
|
uglifyOptions: {
|
|
|
|
compress: isProduction ? {} : false,
|
|
|
|
mangle: isProduction
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
2018-10-13 04:09:45 -04:00
|
|
|
},
|
2018-09-27 15:44:30 -04:00
|
|
|
plugins: [
|
2018-10-19 17:30:23 -04:00
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
|
|
|
from: path.resolve(__dirname, 'node_modules', 'scratch-gui', 'dist', 'static'),
|
|
|
|
to: 'static'
|
|
|
|
}
|
2018-12-12 12:05:19 -05:00
|
|
|
]),
|
|
|
|
new webpack.SourceMapDevToolPlugin({
|
|
|
|
filename: '[file].map'
|
|
|
|
})
|
2018-10-18 22:03:56 -04:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
symlinks: false
|
|
|
|
}
|
2018-09-26 21:16:35 -04:00
|
|
|
};
|