UNPKG

2.87 kBJavaScriptView Raw
1'use strict';
2
3var _ = require('lodash');
4var path = require('path');
5var webpack = require('webpack');
6var ExtractTextPlugin = require('extract-text-webpack-plugin');
7
8module.exports = function (options) {
9 options = _.defaults({}, options, {
10 __dirname: __dirname,
11 displayName: 'TUI',
12 entry: ['./client/index.jsx'],
13 hotloadPort: process.env.HOTLOAD_PORT || 8888
14 });
15
16 options.output = _.defaults({}, options.output, {
17 publicPath: '/static/',
18 filename: 'client.js'
19 });
20
21 options.output.path =
22 path.join(options.__dirname, options.output.publicPath + '/build/')
23
24 var HOTLOAD = process.env.NODE_ENV === 'development';
25
26 var loaders = {
27 es6: {
28 test: /\.(es6|jsx)$/,
29 loaders: ['babel?stage=0'] },
30
31 json: { test: /\.json$/, loaders: ['json'] },
32
33 less: {
34 test: /\.less$/,
35 loader:
36 ExtractTextPlugin.extract(
37 'css!autoprefixer!less', { publicPath: './static/build/' }) },
38
39 markdown: {
40 test: /\.md$/,
41 loaders: 'html!remarkable'}
42 }
43
44 var webpackConfig = {
45 // Hotload Specific Config
46 displayName: options.displayName,
47 hotloadPort: options.hotloadPort,
48
49 // Standard Webpack Config
50 cache: true,
51 devtool: 'source-map',
52 entry: options.entry,
53 module: {
54 loaders: [
55 loaders.es6,
56 loaders.json,
57 loaders.less,
58 loaders.markdown] },
59 output: {
60 path: path.join(options.__dirname, options.output.publicPath + '/build/'),
61 publicPath: options.output.publicPath,
62 filename: options.output.filename },
63 plugins: [
64 // Adds support for 'require(*.less)' from '.jsx' files
65 new ExtractTextPlugin(
66 'style', 'main.css', { disable: false, allChunks: true })],
67 remarkable: {
68 preset: 'full',
69 html: true
70 },
71 resolve: {
72 extensions: ['', '.js', '.jsx', '.es', '.es6'],
73 alias: {app: path.join(options.__dirname, 'client')}
74 },
75 target: 'web'
76 };
77
78 if (HOTLOAD) {
79 webpackConfig.devtool = 'eval-source-map'; // This is not as dirty as it looks. It just generates source maps without being crazy slow.
80 webpackConfig.entry = [
81 'webpack-dev-server/client?http://localhost:' + webpackConfig.hotloadPort,
82 'webpack/hot/dev-server',
83 ].concat(webpackConfig.entry);
84
85 webpackConfig.output.publicPath = 'http://localhost:' +
86 webpackConfig.hotloadPort +
87 webpackConfig.output.publicPath;
88 loaders.es6.loaders = ['react-hot', 'babel?stage=0&optional=runtime'];
89 loaders.less.loader = 'style!css!autoprefixer!less';
90
91 webpackConfig.plugins = [
92 new webpack.HotModuleReplacementPlugin(),
93 new webpack.NoErrorsPlugin()
94 ];
95 }
96
97 webpackConfig.plugins.push(
98 new webpack.optimize.UglifyJsPlugin()
99 );
100
101 return webpackConfig;
102};