UNPKG

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