UNPKG

3.59 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _path = require('path');
8
9var _path2 = _interopRequireDefault(_path);
10
11var _assetsWebpackPlugin = require('assets-webpack-plugin');
12
13var _assetsWebpackPlugin2 = _interopRequireDefault(_assetsWebpackPlugin);
14
15var _webpack = require('webpack');
16
17var _babelRunner = require('babel-runner');
18
19var _projectSettings = require('./projectSettings');
20
21function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23exports.default = function () {
24 var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { creatingBuild: true },
25 getWebpackAssets = _ref.getWebpackAssets,
26 creatingBuild = _ref.creatingBuild,
27 userSettings = _ref.userSettings;
28
29 var namingConvention = creatingBuild ? '[name].[chunkhash]' : '[name]';
30 var customizationOptions = {
31 projectRoot: _projectSettings.projectRoot,
32 creatingBuild: creatingBuild,
33 namingConvention: namingConvention,
34 assetsPath: _projectSettings.assetsPath,
35 publicPath: _projectSettings.publicPath,
36 babelrc: _babelRunner.babelrc
37 };
38
39 // Allow completely extending webpack with `webpack.customize`
40 return userSettings.webpack.customize({
41 entry: {
42 app: [_projectSettings.entryPoint]
43 },
44 output: {
45 path: _projectSettings.assetsPath,
46 filename: namingConvention + '.js',
47 chunkFilename: namingConvention + '.js',
48 publicPath: _projectSettings.publicPath
49 },
50 module: {
51 loaders: [{
52 test: /\.jsx?$/,
53 loaders: ['babel-loader?' + JSON.stringify(_babelRunner.babelrc)],
54 exclude: /(node_modules)|\.route.jsx?$|\.dynamic.jsx?$/
55 }, {
56 test: /\.route.jsx?$|\.dynamic.jsx?$/,
57 loaders: [
58 // `bundle`-loader automatically uses module directly when code is run on the server
59 'bundle-loader?lazy&name=[name]', 'babel-loader?' + JSON.stringify(_babelRunner.babelrc)],
60 exclude: /(node_modules)/
61 }].concat(
62 // Add any user settings from `webpack.loaders`
63 userSettings.webpack.loaders(customizationOptions))
64 },
65 plugins: [new _webpack.DefinePlugin({
66 devToolkitSettings: JSON.stringify(userSettings.devToolkit),
67 // React & Redux rely on this to be set explicitly
68 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
69 })].concat(getWebpackAssets ? [new _assetsWebpackPlugin2.default({
70 path: _projectSettings.assetsManifestFolder,
71 filename: _projectSettings.assetsManifestName,
72 processOutput: getWebpackAssets
73 })] : []).concat(creatingBuild ? [new _webpack.optimize.UglifyJsPlugin()] : [new _webpack.HotModuleReplacementPlugin(), new _webpack.NoEmitOnErrorsPlugin()]).concat(
74 // Add any user settings from `webpack.plugins`
75 userSettings.webpack.plugins(customizationOptions)),
76 resolve: {
77 modules: [
78 // Resolve dev-toolkit related modules like 'webpack-hot-middleware/client'
79 _path2.default.resolve(_projectSettings.devToolkitRoot, 'node_modules'),
80 // Resolve all other modules from client app
81 _path2.default.resolve(_projectSettings.projectRoot, 'node_modules'), 'node_modules']
82 },
83 resolveLoader: {
84 modules: [
85 // Resolve dev-toolkit related webpack loaders like 'babel-loader'
86 _path2.default.resolve(_projectSettings.devToolkitRoot, 'node_modules'),
87 // Resolve webpack loaders related to project
88 _path2.default.resolve(_projectSettings.projectRoot, 'node_modules'), 'node_modules']
89 }
90 }, customizationOptions);
91};
\No newline at end of file