This repository was archived by the owner on Feb 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
132 lines (123 loc) · 3.12 KB
/
webpack.config.js
File metadata and controls
132 lines (123 loc) · 3.12 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
122
123
124
125
126
127
128
129
130
131
132
/* eslint-env node */
const path = require('path');
const { promisify } = require('util');
const cbGlob = require('glob');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const glob = promisify(cbGlob);
module.exports = async ({ analyzeBundle, build, test }) => {
const minimize = analyzeBundle || build;
const devtool = minimize ? 'source-maps' : 'eval-source-maps';
const plugins = [
new HtmlWebpackPlugin({
template: 'index.html',
}),
new CopyWebpackPlugin([
{
from: 'images/**',
},
{
from: 'manifest.json',
},
{
from: 'bower_components/webcomponentsjs/*.js',
flatten: true,
},
{
from: 'service-worker.js',
},
]),
];
if (analyzeBundle) {
plugins.push(new BundleAnalyzerPlugin());
}
if (minimize) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false,
},
output: {
comments: false, // Also removes licences
},
}),
);
}
const filename = test ? '[name].js' : '[name].[chunkhash:8].js';
// Also load all lazy entries during test
const entry = test
? await glob('./src/**/!(*.spec).html')
: './src/my-app.html';
return {
entry,
output: {
path: path.resolve(__dirname, './build'),
filename,
chunkFilename: '[name].[chunkhash:8].js',
},
module: {
loaders: [
{
test: require.resolve(
'./bower_components/polymer-redux/dist/polymer-redux.html',
),
use: [{ loader: 'exports-loader', options: 'PolymerRedux' }],
},
{
test: /\.html$/,
exclude: require.resolve('./index.html'),
use: [
{ loader: 'babel-loader' },
{
loader: 'wc-loader',
options: {
minify: minimize,
},
},
],
},
{
test: /\.(ttf|eot|svg|woff(2)?)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[hash:8].[ext]',
},
},
],
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
query: {
name: '[name].[ext]?[hash]',
},
},
// all files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'
{
test: /\.tsx?$/,
loader: 'ts-loader',
},
],
},
resolve: {
// Add '.ts' and '.tsx' as a resolvable extension.
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
},
plugins,
devServer: {
// serve index.html in place of 404 responses to allow HTML5 history
historyApiFallback: true,
},
devtool,
};
};