This repository has been archived by the owner on Jun 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
121 lines (102 loc) · 2.72 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
/* eslint strict: 0, no-var: 0, object-shorthand: 0 */
'use strict';
var path = require('path');
var glob = require('glob');
var webpack = require('webpack');
var base = __dirname;
var src = path.join(base, 'web');
var appRoot = path.join(src, 'app');
var target = path.join(base, 'target');
var config = {
entry: {
app: ['init.js', 'styles'],
},
resolve: {
root: [appRoot],
alias: {
'styles': path.join(src, 'styles/styles.js'),
},
// we need this to allow to import jsx files like js files (without extension)
extensions: ['', '.js', '.jsx'],
},
output: {
path: null,
filename: 'app.bundle.js',
},
module: {
noParse: ['markdown-it'],
loaders: [
// JS and JSX
{ test: /\.jsx?$/, include: /app/, loaders: [
'react-hot-loader', 'babel-loader?cacheDirectory=true',
] },
// JSON
{ test: /\.json$/, loader: 'json-loader' },
// CSS
{ test: /\.css$/, loader: 'style-loader!css-loader' },
// FONTS
{ test: /\.woff|\.woff2/, loader: 'url-loader?limit=100000' },
],
},
postcss: function () {
return [
require('postcss-import')({
addDependencyTo: this,
resolve: function (id, cssBase) {
return glob.sync(path.join(cssBase, id));
},
}),
require('postcss-mixins'),
require('postcss-nested'),
require('postcss-simple-vars')(),
require('postcss-vertical-rhythm')(),
require('postcss-color-function'),
require('postcss-calc'),
require('autoprefixer')({ browsers: ['last 2 versions'] }),
];
},
plugins: [
new webpack.ProvidePlugin({
'React': 'react',
}),
// do not load moment locales
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
};
if (process.env.NODE_ENV === 'production') {
config.output.path = target;
config.debug = false;
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false,
},
}));
config.plugins.push(new webpack.DefinePlugin({
VITA_PORT: undefined,
DEV: false,
}));
} else if (process.env.NODE_ENV === 'test') {
config.entry.app = glob.sync(path.join(appRoot, '**/*.spec.js?(x)')).map(function (testPath) {
return path.relative(appRoot, testPath);
});
config.output = {
path: target,
filename: 'test.bundle.js',
};
config.target = 'node';
config.debug = true;
config.plugins.push(new webpack.DefinePlugin({
VITA_PORT: 8081,
DEV: false,
}));
} else { // DEVELOPMENT
config.output.path = src;
config.debug = true;
config.devtool = 'eval';
config.plugins.push(new webpack.DefinePlugin({
VITA_PORT: 8081,
DEV: true,
}));
}
module.exports = config;