-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.base.js
More file actions
129 lines (125 loc) · 3.45 KB
/
webpack.config.base.js
File metadata and controls
129 lines (125 loc) · 3.45 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
const webpack = require('webpack')
const path = require('path')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const libraryName = 'FaastUI'
const libraryId = 'faast-ui'
const outputPath = path.resolve('./dist')
module.exports = (env) => {
const plugins = [
new CleanWebpackPlugin([outputPath]),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env)
}),
new webpack.optimize.OccurrenceOrderPlugin(),
]
let outputFile
let outputCssFile
let cssIdentName
if (env === 'production') {
plugins.push(new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
minimize: true,
compress: {
warnings: false
},
mangle: true
}
}))
outputFile = 'js/[name].min.js'
outputCssFile = 'css/[name].min.css'
cssIdentName = '[name]-[hash:base64:6]'
} else {
outputFile = 'js/[name].js'
outputCssFile = 'css/[name].css'
cssIdentName = '[name]__[local]__[hash:base64:6]'
}
plugins.push(new ExtractTextPlugin({
filename: outputCssFile,
allChunks: true,
}), new OptimizeCssAssetsPlugin())
const config = {
entry: {
[libraryId]: path.resolve('./src/index.js')
},
devtool: 'source-map',
output: {
path: outputPath,
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader?cacheDirectory', 'eslint-loader'],
}, {
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader', // translates CSS into CommonJS modules
options: {
minimize: false, // CSS minification handled by OptimizeCssAssetsPlugin
sourceMap: true,
importLoaders: 2,
localIdentName: cssIdentName
}
}, {
loader: 'postcss-loader', // Run post css actions
options: {
sourceMap: true,
plugins: () => [ // post css plugins, can be exported to postcss.config.js
require('precss'),
require('autoprefixer')
],
}
}, {
loader: 'sass-loader', // compiles SASS to CSS
options: {
sourceMap: true,
includePaths: [path.resolve('./node_modules')],
sourceMapContents: true,
outputStyle: 'expanded',
precision: 6
}
}]
})
}]
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
},
reactstrap: {
root: 'Reactstrap',
commonjs2: 'reactstrap',
commonjs: 'reactstrap',
amd: 'reactstrap'
}
},
resolve: {
alias: {
Components: path.resolve('./src/components'),
},
extensions: ['.js', '.jsx', '.css', '.scss']
},
plugins,
}
return config
}