2016-10-17 22:00:29 +13:00
|
|
|
|
2017-03-08 09:13:24 +13:00
|
|
|
const isDev = process.env.NODE_ENV !== "production";
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
2016-10-03 14:44:27 +13:00
|
|
|
|
2017-03-08 09:13:24 +13:00
|
|
|
const node_dir = path.resolve(__dirname, 'node_modules');
|
|
|
|
|
const output_dir = path.resolve(__dirname, 'mopidy_iris/static');
|
2016-10-03 14:44:27 +13:00
|
|
|
|
2017-03-08 09:13:24 +13:00
|
|
|
const config = {
|
2016-10-03 14:44:27 +13:00
|
|
|
|
2017-03-08 09:13:24 +13:00
|
|
|
context: path.resolve(__dirname),
|
|
|
|
|
|
|
|
|
|
entry: {
|
|
|
|
|
js: './src/js/index'
|
|
|
|
|
},
|
2016-10-03 14:44:27 +13:00
|
|
|
|
|
|
|
|
output: {
|
2017-03-08 09:13:24 +13:00
|
|
|
path: path.resolve(__dirname, 'mopidy_iris/static'),
|
2016-10-03 14:44:27 +13:00
|
|
|
filename: 'app.js'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
module: {
|
2017-03-08 09:13:24 +13:00
|
|
|
rules: [
|
2016-10-17 22:00:29 +13:00
|
|
|
{
|
2017-03-08 09:13:24 +13:00
|
|
|
test: require.resolve('jquery'),
|
|
|
|
|
exclude: [
|
|
|
|
|
/node_modules/
|
|
|
|
|
],
|
|
|
|
|
use: 'expose-loader?jQuery!expose?$'
|
2016-10-17 22:00:29 +13:00
|
|
|
},
|
2016-10-03 14:44:27 +13:00
|
|
|
{
|
2017-03-08 09:13:24 +13:00
|
|
|
// JSX
|
2016-10-03 14:44:27 +13:00
|
|
|
test: /\.js$/,
|
|
|
|
|
exclude: [
|
2017-03-08 09:13:24 +13:00
|
|
|
/node_modules/,
|
2016-10-03 14:44:27 +13:00
|
|
|
'index.js',
|
|
|
|
|
],
|
2017-03-08 09:13:24 +13:00
|
|
|
use: {
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: {
|
|
|
|
|
presets: [
|
|
|
|
|
'react',
|
|
|
|
|
'es2015',
|
|
|
|
|
'stage-2'
|
|
|
|
|
]
|
|
|
|
|
}
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.scss$/,
|
2017-03-08 09:13:24 +13:00
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
|
fallback: 'style-loader',
|
|
|
|
|
//resolve-url-loader may be chained before sass-loader if necessary
|
|
|
|
|
use: ['css-loader', 'sass-loader']
|
|
|
|
|
})
|
2016-10-17 22:00:29 +13:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
// load external resources (ie Google fonts)
|
2016-12-18 11:32:03 +13:00
|
|
|
test: /.(gif|png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
|
2017-03-08 09:13:24 +13:00
|
|
|
use: {
|
|
|
|
|
loader: 'url-loader',
|
|
|
|
|
options: {
|
|
|
|
|
'limit': 100000
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
|
$: "jquery",
|
|
|
|
|
jQuery: "jquery",
|
|
|
|
|
"window.jQuery": "jquery"
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Development-only configuration values
|
|
|
|
|
**/
|
2017-03-08 09:13:24 +13:00
|
|
|
if (isDev){
|
2016-10-03 14:44:27 +13:00
|
|
|
|
|
|
|
|
// set compiled css location
|
|
|
|
|
config.plugins.push( new ExtractTextPlugin("app.css") );
|
|
|
|
|
|
|
|
|
|
// we want source maps
|
|
|
|
|
config.devtool = 'source-map';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Production-only configuration values
|
|
|
|
|
**/
|
2017-03-08 09:13:24 +13:00
|
|
|
} else {
|
2016-10-03 14:44:27 +13:00
|
|
|
|
|
|
|
|
// set our final output filename
|
|
|
|
|
config.output.filename = 'app.min.js';
|
|
|
|
|
|
|
|
|
|
// re-iterate our production value as a string (for ReactJS building)
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
'process.env':{
|
|
|
|
|
'NODE_ENV': JSON.stringify('production')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// remove all debug and console code
|
2017-03-08 09:13:24 +13:00
|
|
|
config.module.rules.push(
|
2016-10-03 14:44:27 +13:00
|
|
|
{
|
2017-03-08 09:13:24 +13:00
|
|
|
test: /\.(js)$/,
|
|
|
|
|
use: {
|
|
|
|
|
loader: 'webpack-strip',
|
|
|
|
|
options: {
|
|
|
|
|
strip: ['console.log', 'console.info', 'debug']
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// set compiled css location
|
|
|
|
|
config.plugins.push( new ExtractTextPlugin("app.min.css") );
|
|
|
|
|
|
|
|
|
|
// uglify our js, with no sourcemaps
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
|
compress: true,
|
|
|
|
|
mangle: false,
|
|
|
|
|
sourceMap: false,
|
|
|
|
|
comments: false
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now export our collated config object
|
|
|
|
|
module.exports = config;
|