-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
123 lines (104 loc) · 3.07 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
'use strict';
var path = require('path');
var webpack = require('webpack');
// Detect if we're running webpack dev server or building a distribution.
var devServer = path.basename(require.main.filename) === 'webpack-dev-server.js';
// Detect if the webpack dev server should run the IFrame version.
var nestedIFrame = JSON.parse(process.env.NESTED_IFRAME || 'false');
var config = {
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
],
entry: './src/scripts/index.js',
output: {
filename: 'main.js',
path: 'dist/'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
// JSZip is bundled with xlsx as a pre-built javascript file. It probably
// also doesn't make sense to parse the pre-uglified Madeline JS (this has
// not been tested thoroughly).
noParse: [/\/jszip\.js$/, /\/madeline\.js$/],
preLoaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'eslint'
}],
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loaders: ['babel?' + JSON.stringify({
presets: ['es2015', 'react', 'stage-1'],
plugins: ['transform-runtime'],
cacheDirectory: true
})]
}, {
test: /\.css$/,
loaders: ['style', 'css']
}, {
test: /\.less$/,
// The mergeRules transformation breaks our zoom slider thumb.
// https://github.com/ben-eb/postcss-merge-rules/issues/18
loaders: ['style', 'css?-mergeRules', 'less']
}, {
test: /\.(png|jpg)$/,
loader: 'url?limit=8192'
}, {
test: /\.json$/,
loader: 'json'
}, {
test: /\.pegjs$/,
loader: 'pegjs'
}, {
test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url?limit=10000&mimetype=application/font-woff'
}, {
test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url?limit=10000&mimetype=application/font-woff2'
}, {
test: /\.(otf|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file'
}]
},
cache: false,
debug: false,
devtool: false
};
if (devServer) {
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
Nested: nestedIFrame ? '../src/scripts/components/FramedEditor' : '../src/scripts/index'
}),
new webpack.DefinePlugin({
__NESTED_IFRAME__: nestedIFrame,
'process.env.NODE_ENV': '"development"'
})
);
config.entry = [
'webpack/hot/only-dev-server',
'./example/init.jsx'
];
config.devServer = {
contentBase: './example',
hot: true
};
config.output.publicPath = '/dist/';
config.module.loaders[0].loaders.unshift('react-hot');
config.cache = true;
config.debug = true;
config.devtool = 'eval';
} else {
config.plugins.push(
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({compress: {drop_console: false}}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.DefinePlugin({'process.env.NODE_ENV': '"production"'})
);
}
module.exports = config;