-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.common.js
88 lines (84 loc) · 2.88 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
/* eslint-env node */
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: 'src/index.html',
filename: 'index.html',
title: 'JS Example Project',
inject: 'body'
});
const pack = require('./package.json');
const appName = pack.name;
const appVersion = pack.version;
const buildNumber = process.env.BUILD_NUMBER || 'local_dev';
const WebpackShellPlugin = require('webpack-shell-plugin');
const buildsDir = path.resolve(__dirname, 'builds');
const distDir = path.resolve(__dirname, 'dist')
const ENSURE_BUILDS_DIR = 'test -d '+buildsDir+' || mkdir '+buildsDir;
const ENSURE_DIST_DIR = 'test -d '+distDir+' || mkdir '+distDir
const MERGE_ASSET_COMPILE = '[ -d assets ] && cp -R '+path.join('assets', '*')+' "'+distDir+'" || true';
const CREATE_ARCHIVE = 'uname -a | grep -iqv cygwin && tar czvf '+path.join(buildsDir, appName+'-'+appVersion+'-b'+buildNumber+'.tar.gz')+' -C '+distDir+' . || echo "skipping archive creation, unsupported platform"';
module.exports = {
entry: './src/index.jsx',
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.jsx$|\.js$/,
enforce: 'pre',
loader: 'eslint-loader',
include: __dirname+'/src',
exclude: __dirname+'/node_modules'
},
{
test: /\.jsx$|\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpe?g|gif)$/i,
loader: 'url-loader?limit=100000'
},
{
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/octet-stream'
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader'
},
{
test: /\.otf$/,
loader: 'file-loader'
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
}
]
},
plugins: [
HtmlWebpackPluginConfig,
new WebpackShellPlugin({
onBuildStart: [ENSURE_BUILDS_DIR, ENSURE_DIST_DIR],
onBuildExit: [MERGE_ASSET_COMPILE, CREATE_ARCHIVE],
safe: true
})
],
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: 'bundle.js'
}
}