-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
executable file
·108 lines (100 loc) · 3.57 KB
/
webpack.common.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
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var pkgBower = require('./package.json');
var baseHref = process.env.WP_BASE_HREF ? process.env.WP_BASE_HREF : '/';
module.exports = {
entry: {
'vendor': './app/Vendor.jsx',
'app': './app/App.jsx'
},
resolve: {
root: path.join(__dirname, ''),
modulesDirectories: ['node_modules', 'bower_components'],
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [{
test: /jquery\.flot\.resize\.js$/,
loader: 'imports?this=>window'
}, {
test: /\.js/,
loader: 'imports?define=>false'
}, {
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: ['react-hot']
}, {
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
compact: false
}
}, {
test: /\.css$/,
exclude: path.join(process.cwd(), '/app'),
loader: ExtractTextPlugin.extract('style', 'css?sourceMap')
}, {
test: /\.css$/,
include: path.join(process.cwd(), '/app'),
loader: 'raw'
}, {
test: /\.woff|\.woff2|\.svg|.eot|\.ttf/,
loader: 'url?prefix=font/&limit=10000'
}, {
test: /\.(png|jpg|gif)$/,
loader: 'url?limit=10000'
}, {
test: /\.scss$/,
loader: 'style!css!sass?outputStyle=expanded'
// loader: 'style!css!rtlcss-loader!sass?outputStyle=expanded' // uncomment for RTL
}]
// , noParse: [/\.min\.js/]
},
resolveLoader: {
alias: {
'rtlcss-loader': path.join(__dirname, 'rtlcss-loader.js')
}
},
devServer: {
outputPath: path.join(__dirname, 'dist')
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor[hash:6].js'),
new HtmlWebpackPlugin({
template: 'app/index.html',
baseUrl: baseHref
}),
new webpack.ResolverPlugin([
// new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('package.json', ['main']),
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('.bower.json', ['main'])
]),
new CopyWebpackPlugin([{
from: 'img',
to: 'img',
context: path.join(__dirname, 'app')
}, {
from: 'server',
to: 'server',
context: path.join(__dirname, 'app')
}, {
from: 'fonts',
to: 'fonts',
context: path.join(__dirname, 'app')
}]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
// https://github.com/moment/moment/issues/2979#issuecomment-189899510
new webpack.ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /js$/),
new webpack.DefinePlugin({
WP_BASE_HREF: JSON.stringify(baseHref)
})
]
};