-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.example.config.js
More file actions
90 lines (82 loc) · 2.08 KB
/
webpack.example.config.js
File metadata and controls
90 lines (82 loc) · 2.08 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
'use strict';
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const env = JSON.stringify(process.env.NODE_ENV);
const localDev = !env || env === 'development';
const htmlPluginMinify = localDev ?
{} :
{
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
};
const plugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: 'example/base.html',
filename: localDev ? 'index.html' : '../index.html',
minify: htmlPluginMinify
})
];
let entry = ['./example/index.js'];
if (localDev) {
plugins.push(new webpack.NamedModulesPlugin());
plugins.push(new webpack.HotModuleReplacementPlugin());
entry = [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3001',
'webpack/hot/only-dev-server'
].concat(entry);
} else {
plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true
}));
}
module.exports = {
output: {
path: path.join(__dirname, 'dist/assets'),
filename: localDev ? '[name].js' : '[name]-[hash].js',
publicPath: localDev ? 'http://localhost:3001/' : '//cdn.llscdn.com/hybrid/lls-web-recorder/'
},
cache: true,
devtool: 'eval',
entry,
devServer: {
host: 'localhost',
port: 3001,
hot: true,
contentBase: './example'
},
module: {
rules: [{
oneOf: [{
test: /\.worker\.js$/,
loader: require.resolve('worker-loader'),
options: {
inline: true,
fallback: false
}
}, {
test: /\.js?$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader'),
options: {
cacheDirectory: true
}
}, {
test: /\.(css|scss)$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
}]
}]
},
plugins
};