-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpackfile.js
89 lines (85 loc) · 2.74 KB
/
webpackfile.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
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (env = {}) => {
const srcDir = path.join(__dirname, 'src/client');
const distDir = env.dist ? path.join(process.cwd(), env.dist) : path.join(__dirname, 'target/client');
const config = {
context: srcDir,
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
presets: ['es2015', 'stage-2', 'react']
}
}]
},{
test: /\.css$/,
loader: 'style-loader!css-loader?modules&camelCase'
},{
test: /\.html$/,
loader: 'file-loader?name=[path][name].[ext]!extract-loader!html-loader'
}]
},
plugins: [
new webpack.LoaderOptionsPlugin({
test: /\.css$/,
options: {
postcss: [
require('stylelint'),
require('autoprefixer')({ browsers: ['defaults'] })
]
}
}),
new webpack.DefinePlugin({
'RADIOBOX_DEBUG': JSON.stringify(process.env.DEBUG || ''),
'RADIOBOX_HOST': JSON.stringify(process.env.HOST || '')
}),
new webpack.ProvidePlugin({
URL: 'url-parse'
}),
new CopyWebpackPlugin([
{from:'icons',to:'icons'}
]),
new CopyWebpackPlugin([
{from:'../server',to:'../'}
]),
new CopyWebpackPlugin([
{from:'manifest.json',to:'manifest.json'}
])
],
output: {
filename: 'index.js',
path: distDir,
devtoolModuleFilenameTemplate: function(info) {
// HACK use path.relative twice
const filename = path.relative(__dirname, info.absoluteResourcePath);
return path.relative(__dirname, filename);
}
},
resolve: {
extensions: ['.js', '.jsx']
},
performance: {
hints: false
},
devServer: {
contentBase: distDir,
noInfo: true,
port: 8000
},
// TODO https://github.com/webpack/webpack/issues/2145
devtool: env.devtool || 'inline-source-map'
};
if (env.karma) {
// do nothing
} else {
Object.assign(config, {
entry: ['./index.jsx', './index.html']
});
}
return config;
};