1 | 'use strict';
|
2 |
|
3 | var _ = require('lodash');
|
4 | var path = require('path');
|
5 | var webpack = require('webpack');
|
6 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
|
7 |
|
8 | module.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 | loader: 'html!markdown'}
|
42 | }
|
43 |
|
44 | var webpackConfig = {
|
45 |
|
46 | displayName: options.displayName,
|
47 | hotloadPort: options.hotloadPort,
|
48 |
|
49 |
|
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 |
|
65 | new ExtractTextPlugin(
|
66 | 'style', 'main.css', { disable: false, allChunks: true })],
|
67 | resolve: {
|
68 | extensions: ['', '.js', '.jsx', '.es', '.es6'],
|
69 | alias: {app: path.join(options.__dirname, 'client')}
|
70 | },
|
71 | target: 'web'
|
72 | };
|
73 |
|
74 | if (HOTLOAD) {
|
75 | webpackConfig.devtool = 'eval-source-map';
|
76 | webpackConfig.entry = [
|
77 | 'webpack-dev-server/client?http://localhost:' + webpackConfig.hotloadPort,
|
78 | 'webpack/hot/dev-server',
|
79 | ].concat(webpackConfig.entry);
|
80 |
|
81 | webpackConfig.output.publicPath = 'http://localhost:' +
|
82 | webpackConfig.hotloadPort +
|
83 | webpackConfig.output.publicPath;
|
84 | loaders.es6.loaders = ['react-hot', 'babel?stage=0&optional=runtime'];
|
85 | loaders.less.loader = 'style!css!autoprefixer!less';
|
86 |
|
87 | webpackConfig.plugins = [
|
88 | new webpack.HotModuleReplacementPlugin(),
|
89 | new webpack.NoErrorsPlugin()
|
90 | ];
|
91 | }
|
92 |
|
93 | webpackConfig.plugins.push(
|
94 | new webpack.optimize.UglifyJsPlugin()
|
95 | );
|
96 |
|
97 | return webpackConfig;
|
98 | };
|