forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
116 lines (106 loc) · 2.92 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***** WARNING: ES5 code only here. Not transpiled! *****/
/**
* External dependencies
*/
var webpack = require( 'webpack' ),
path = require( 'path' );
/**
* Internal dependencies
*/
var config = require( './server/config' ),
ChunkFileNamePlugin = require( './server/bundler/plugin' );
/**
* Internal variables
*/
var CALYPSO_ENV = process.env.CALYPSO_ENV || 'development',
PORT = process.env.PORT || 3000,
jsLoader,
webpackConfig;
webpackConfig = {
cache: true,
entry: {},
output: {
path: path.join( __dirname, 'public' ),
publicPath: '/calypso/',
filename: '[name].[hash].js',
chunkFilename: '[name].[chunkhash].js',
devtoolModuleFilenameTemplate: 'app:///[resource-path]'
},
devtool: '#eval',
module: {
loaders: [
{
test: /sections.js$/,
exclude: 'node_modules',
loader: path.join( __dirname, 'server', 'bundler', 'loader' )
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
include: require.resolve( 'tinymce/tinymce' ),
loader: 'exports?window.tinymce',
},
{
include: /node_modules\/tinymce/,
loader: 'imports?this=>window',
}
]
},
resolve: {
extensions: [ '', '.json', '.js', '.jsx' ],
modulesDirectories: [ 'node_modules', path.join( __dirname, 'client' ), path.join( __dirname, 'shared' ) ]
},
node: {
console: false,
process: true,
global: true,
Buffer: true,
__filename: 'mock',
__dirname: 'mock',
fs: 'empty'
},
plugins: [
new webpack.DefinePlugin( {
'process.env': {
NODE_ENV: JSON.stringify( config( 'env' ) )
}
} ),
new webpack.optimize.OccurenceOrderPlugin( true ),
new webpack.IgnorePlugin( /^props$/ ),
new webpack.IgnorePlugin( /^\.\/locale$/, /moment$/ )
],
externals: [ 'electron' ]
};
if ( CALYPSO_ENV === 'desktop' || CALYPSO_ENV === 'desktop-mac-app-store' ) {
webpackConfig.output.filename = '[name].js';
} else {
webpackConfig.entry.vendor = [ 'react', 'store', 'page', 'wpcom-unpublished', 'jed', 'debug' ];
webpackConfig.plugins.push( new webpack.optimize.CommonsChunkPlugin( 'vendor', '[name].[hash].js' ) );
webpackConfig.plugins.push( new ChunkFileNamePlugin() );
}
jsLoader = {
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: [ 'babel-loader?cacheDirectory&optional[]=runtime' ]
};
if ( CALYPSO_ENV === 'development' ) {
webpackConfig.plugins.push( new webpack.HotModuleReplacementPlugin() );
webpackConfig.entry[ 'build-' + CALYPSO_ENV ] = [
'webpack-dev-server/client?http://calypso.localhost:' + PORT,
'webpack/hot/only-dev-server',
path.join( __dirname, 'client', 'boot' )
];
// Add react hot loader before babel-loader
jsLoader.loaders = [ 'react-hot' ].concat( jsLoader.loaders );
} else {
webpackConfig.entry[ 'build-' + CALYPSO_ENV ] = path.join( __dirname, 'client', 'boot' );
webpackConfig.devtool = false;
}
webpackConfig.module.loaders = [ jsLoader ].concat( webpackConfig.module.loaders );
module.exports = webpackConfig;