forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
133 lines (122 loc) · 3.41 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***** WARNING: ES5 code only here. Not transpiled! *****/
/**
* External dependencies
*/
var webpack = require( 'webpack' ),
path = require( 'path' );
/**
* Internal dependencies
*/
var config = require( './server/config' ),
sections = require( './client/sections' ),
ChunkFileNamePlugin = require( './server/bundler/plugin' ),
PragmaCheckPlugin = require( 'server/pragma-checker' );
/**
* Internal variables
*/
var CALYPSO_ENV = process.env.CALYPSO_ENV || 'development',
jsLoader,
webpackConfig;
const sectionCount = sections.length;
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' ],
root: [ path.join( __dirname, 'client' ) ],
modulesDirectories: [ 'node_modules' ]
},
resolveLoader: {
root: [ __dirname ]
},
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', 'jed', 'debug' ];
webpackConfig.plugins.push( new webpack.optimize.CommonsChunkPlugin( 'vendor', '[name].[hash].js' ) );
webpackConfig.plugins.push( new webpack.optimize.CommonsChunkPlugin( {
children: true,
minChunks: Math.floor( sectionCount * 0.25 ),
async: true,
filename: 'commons.[hash].js'
} ) );
webpackConfig.plugins.push( new ChunkFileNamePlugin() );
// jquery is only needed in the build for the desktop app
// see electron bug: https://github.com/atom/electron/issues/254
webpackConfig.externals.push( 'jquery' );
}
jsLoader = {
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: [ 'babel-loader?cacheDirectory&optional[]=runtime' ]
};
if ( CALYPSO_ENV === 'development' ) {
webpackConfig.plugins.push( new PragmaCheckPlugin() );
webpackConfig.plugins.push( new webpack.HotModuleReplacementPlugin() );
webpackConfig.entry[ 'build-' + CALYPSO_ENV ] = [
'webpack-dev-server/client?/',
'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;