This repository has been archived by the owner on Aug 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
101 lines (97 loc) · 2.43 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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = (env) => {
// プロダクションビルド判定
const nodeEnv = env && env.prod ? 'production' : 'development';
const isProd = nodeEnv === 'production';
// プラグイン設定
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.bundle.js'
}),
new ExtractTextPlugin({
filename: "bundle.css",
allChunks: true
}),
new HtmlWebpackPlugin({
inject: 'head',
template: path.join(__dirname, '/src/index.ejs'),
filename: path.join(__dirname, '/www/index.html'),
minify: {
removeComments: isProd
}
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv)
}
})
];
// プロダクションビルド用プラグイン追加
if (isProd) {
plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false,
}
})
);
}
return {
entry: {
app: path.join(__dirname, '/src/js/app.js'),
vendor: ['angular', 'onsenui'],
},
output: {
path: path.join(__dirname, '/www/assets'),
filename: 'bundle.js',
},
devtool: isProd ? false : 'inline-source-map',
resolve: {
extensions: [".html", ".js", ".json", ".css", ".scss"],
},
plugins,
module: {
rules: [{
test: /\.(css|scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader']
})
}, {
test: /\.(otf|eot|svg|ttf|woff|woff2)(\?.+)?$/,
use: ['url-loader']
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
use: ['url-loader']
}, {
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: ['babel-loader']
}, {
test: /\.html?$/,
use: [
{
loader: 'ngtemplate-loader',
options: {
relativeTo: path.join(__dirname, '/src/')
}
},
{
loader: 'html-loader',
options: {
minimize: isProd
}
}]
}
]
}
};
};