2017-05-22 22:49:20 +02:00
|
|
|
var path = require('path');
|
2017-05-25 19:37:07 +02:00
|
|
|
var assets = require('./webpack.assets.json');
|
2017-07-28 22:53:37 +02:00
|
|
|
var BundleTracker = require('webpack-bundle-tracker');
|
|
|
|
var webpack = require('webpack');
|
2017-05-22 22:49:20 +02:00
|
|
|
|
2017-07-28 22:53:37 +02:00
|
|
|
|
|
|
|
module.exports = function (env) {
|
|
|
|
var production = env === "production";
|
|
|
|
var config = {
|
2017-07-28 22:33:40 +02:00
|
|
|
context: path.resolve(__dirname, "../"),
|
|
|
|
entry: assets,
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
// Run the typescript compilier on .ts files before webpack
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
loader: 'ts-loader',
|
|
|
|
},
|
|
|
|
// This loads and transforms sourcemap files from other compiliers.
|
2017-07-28 22:53:37 +02:00
|
|
|
// The typescript comilier will generate a sourcemap and
|
|
|
|
// source-map-loader will output the correct sourcemap from that.
|
2017-07-28 22:33:40 +02:00
|
|
|
{
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: "source-map-loader",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
use: "source-map-loader",
|
|
|
|
},
|
|
|
|
// Uses script-loader on minified files so we don't change global variables in them.
|
|
|
|
// Also has the effect of making processing these files fast
|
|
|
|
{
|
|
|
|
test: /(min|zxcvbn)\.js/,
|
|
|
|
use: [ 'script-loader' ],
|
|
|
|
},
|
|
|
|
// Expose Global variables to webpack
|
|
|
|
{
|
|
|
|
test: require.resolve('../static/js/debug.js'),
|
|
|
|
use: [
|
|
|
|
{loader: 'expose-loader', options: 'debug'},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: require.resolve('../static/js/blueslip.js'),
|
|
|
|
use: [
|
|
|
|
{loader: 'expose-loader', options: 'blueslip'},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: require.resolve('../static/js/common.js'),
|
|
|
|
use: [
|
|
|
|
{loader: 'expose-loader', options: 'common'},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, '../static/webpack-bundles'),
|
2017-07-28 22:53:37 +02:00
|
|
|
filename: production ? '[name]-[hash].js' : '[name].js',
|
2017-07-28 22:33:40 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: [".tsx", ".ts", ".js", ".json"],
|
|
|
|
},
|
2017-07-28 22:53:37 +02:00
|
|
|
devtool: production ? 'source-map' : 'eval',
|
2017-07-28 22:33:40 +02:00
|
|
|
};
|
2017-07-28 22:53:37 +02:00
|
|
|
if (production) {
|
|
|
|
config.plugins = [
|
|
|
|
new BundleTracker({filename: 'webpack-stats-production.json'}),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// Built webpack dev asset reloader
|
|
|
|
config.entry.common.unshift('webpack/hot/dev-server');
|
|
|
|
// Use 0.0.0.0 so that we can set a port but still use the host
|
|
|
|
// the browser is connected to.
|
|
|
|
config.entry.common.unshift('webpack-dev-server/client?http://0.0.0.0:9994');
|
|
|
|
|
|
|
|
// Out JS debugging tools
|
|
|
|
config.entry.common.push('./static/js/debug.js');
|
|
|
|
|
|
|
|
config.output.publicPath = '/webpack/';
|
|
|
|
config.plugins = [
|
|
|
|
new BundleTracker({filename: 'var/webpack-stats-dev.json'}),
|
|
|
|
// Hot Reload of code in development
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
// Better logging from console for hot reload
|
|
|
|
new webpack.NamedModulesPlugin(),
|
|
|
|
// script-loader should load sourceURL in dev
|
|
|
|
new webpack.LoaderOptionsPlugin({debug: true}),
|
|
|
|
];
|
|
|
|
|
|
|
|
config.devServer = {
|
|
|
|
clientLogLevel: "warning",
|
|
|
|
hot: true,
|
|
|
|
inline: false,
|
|
|
|
stats: "errors-only",
|
|
|
|
watchOptions: {
|
|
|
|
aggregateTimeout: 300,
|
|
|
|
poll: 1000,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2017-07-28 22:33:40 +02:00
|
|
|
return config;
|
2015-10-26 17:11:44 +01:00
|
|
|
};
|