-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
121 lines (115 loc) · 4.32 KB
/
webpack.config.js
File metadata and controls
121 lines (115 loc) · 4.32 KB
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
'use strict';
var webpack = require('webpack');
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
/**
* Env
* Get npm lifecycle event to identify the environment
*/
var ENV = process.env.NODE_ENV;
var isTest = ENV === 'test' || ENV === 'test-watch';
var isProd = ENV === 'production';
var webpackConfig = {
entry: {
app: ['./src/scripts/app']
},
output: {
path: __dirname + '/www/',
publicPath: './',
filename: isProd ? 'scripts/[name].[hash].bundle.js' : 'scripts/[name].bundle.js',
chunkFilename: isProd ? 'scripts/[id].[name].[chunkhash].chunk.js' : 'scripts/[id].[name].chunk.js',
sourceMapFilename: '[file].map',
pathinfo: isProd ? false : true
},
devtool: 'source-map',
externals: {
'angular': 'angular',
'angular-route': 'angular-route',
'onsenui': 'onsenui',
'ocLazyLoad': 'ocLazyLoad'
},
resolve: {
modulesDirectories: ['src/web_modules', 'node_modules', 'src/bower_components'],
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
},
module: {
loaders: [
// TypeScript loader
// Reference: https://github.com/TypeStrong/ts-loader
// Transpile .ts files using TypeScript
{
test: /\.ts$/,
loader: 'ts-loader'
}, {
// CSS LOADER
// Reference: https://github.com/webpack/css-loader
// Allow loading css through js
//
// Reference: https://github.com/postcss/postcss-loader
// Postprocess your css with PostCSS plugins
test: /\.css$/,
// Reference: https://github.com/webpack/extract-text-webpack-plugin
// Extract css files in production builds
//
// Reference: https://github.com/webpack/style-loader
// Use style-loader in development.
loader: isTest ? 'null' : ExtractTextPlugin.extract('style', 'css?sourceMap', {publicPath: "../"})
}, {
// ASSET LOADER
// Reference: https://github.com/webpack/file-loader
// Copy png, jpg, jpeg, gif, svg, woff, woff2, ttf, eot files to output
// Rename the file using the asset hash
// Pass along the updated reference to your code
// You can add here any file extension you want to get copied to your output
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|eot)$/,
loader: 'url-loader?limit=8192'
}, {
test: /\.(ttf)$/,
loader: 'file-loader?name=css/font/[hash].[ext]'
}
// {
// // HTML LOADER
// // Reference: https://github.com/webpack/raw-loader
// // Allow loading html through js
// test: /\.html$/,
// loader: 'raw'
// }
]
},
plugins: [
// function() {
// this.plugin('done', function(stats) {
// require('fs').writeFileSync(
// path.join(__dirname, './', 'stats.json'),
// JSON.stringify(stats.toJson()));
// });
// },
new webpack.ResolverPlugin(
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', ['main'])
),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: isProd ? 'scripts/common.[hash].js' : 'scripts/common.js'
}),
new HtmlWebpackPlugin({
template: './src/index.html',
minify: isProd ? {
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true
} : {},
inject: false
}),
new ExtractTextPlugin(isProd ? "css/app.[contenthash].bundle.css" : "css/app.bundle.css", {
allChunks: true
})
],
isProd: isProd,
isTest: isTest
};
module.exports = webpackConfig;