forked from morsdyce/mimic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
133 lines (113 loc) · 3.12 KB
/
Copy pathwebpack.config.js
File metadata and controls
133 lines (113 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
133
'use strict';
const webpack = require('webpack');
const path = require('path');
const CleanPlugin = require('clean-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const appEnv = process.env.NODE_ENV || 'development';
const libPath = path.join(__dirname, 'lib');
const distPath = path.join(__dirname, 'dist');
const assetsPathPattern = '[path][name].[hash].[ext]';
const distFilePattern = '[name].js';
const packageConfig = require('./package.json');
let config = {
// The base directory for resolving `entry` (must be absolute path)
context: libPath,
entry: {
'mimic.api': ['api/index.js'],
'mimic.worker': ['api/worker.js'],
'mimic.remote': ['api/remote.js'],
'mimic': 'index.js'
},
// Options affecting the resolving of modules
resolve: {
// Enable resolving modules relative to these paths
modules: [
libPath,
'node_modules'
],
extensions: ['.webpack.js', '.js']
},
output: {
// The bundling output directory (must be absolute path)
path: distPath,
// The output filename of the entry chunk, relative to `path`
// [name] - Will be set per each key name in `entry`
filename: distFilePattern,
libraryTarget: 'umd',
library: 'mimic'
},
module: {
rules: [
// Babel
{
test: /\.jsx?$/,
loader: 'babel-loader',
include: [
path.resolve('lib'),
path.resolve('node_modules/preact-compat/src')
]
},
// SCSS
{
test: /\.(css|scss)$/,
use: [
'css-loader',
'autoprefixer-loader',
'sass-loader?includePaths[]=' + encodeURIComponent(libPath)
]
},
// Allow `require`ing image/font files (also when included in CSS)
// Inline assets under 5kb as Base64 data URI, otherwise uses `file-loader`
{
test: /\.(jpe?g|png|gif|eot|woff2?|ttf|svg)(\?.*)?$/i,
loader: 'url-loader?limit=999999&name=' + assetsPathPattern
}
]
},
plugins: [
// Define global variables that will be available in any chunk
new webpack.DefinePlugin({
__VERSION: JSON.stringify(packageConfig.version),
__ENV: JSON.stringify(appEnv),
'process.env': {
'NODE_ENV': JSON.stringify(appEnv)
}
})
],
devServer: {
contentBase: libPath,
noInfo: true,
inline: true
}
};
if (appEnv !== 'production') {
config.devtool = '#inline-source-map';
}
if (appEnv === 'production') {
config.plugins.push(
// Remove build related folders
new CleanPlugin(['dist']),
new LodashModuleReplacementPlugin({
paths: true,
shorthands: true,
collections: true
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
warnings: false,
screw_ie8: true
},
comments: false
})
);
}
module.exports = config;