-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
128 lines (113 loc) · 3.37 KB
/
webpack.config.js
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
require('babel-register');
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const autoprefixer = require('autoprefixer');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
const pkg = require('./package');
// Check if watching so that prerendering can be disabled.
const watching = process.argv[1] && process.argv[1].indexOf('webpack-dev-server') !== -1;
let paths = ['/'];
/**
*
* Loaders
*
*/
const JS_LOADER = {
test: /\.jsx?$/,
include: [
path.resolve('./src'),
path.resolve('./node_modules/camelcase')
],
loaders: ['babel']
};
const JSON_LOADER = {
test: /\.json$/,
loader: 'json-loader'
};
const GRAPHQL_LOADER = {
test: /\.graphql$/,
loaders: ['raw-loader']
};
const FILE_LOADER = {
test: /\.png$|\.svg$|\.jpg$|\.gif$|\.ttf$|\.woff$|\.woff2$|\.eot$|\.otf$/,
loaders: ['file-loader'],
loader: 'file?name=assets/[hash].[ext]'
};
const development = {
devtool: 'source-map',
entry: Object.assign({}, {
// 'fetch': 'whatwg-fetch',
[pkg.name]: './src/semantic-fauna/client.js'
}, watching ? {} : { // Don't have prerender entry if watching
__prerender: './src/semantic-fauna/prerender.js',
}),
output: {
path: './docs',
filename: '[name].js',
publicPath: '/',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['', '.jsx', '.js'],
modulesDirectories: ['src', 'node_modules']
},
plugins: [
new webpack.DefinePlugin({'process.env': JSON.stringify(Object.assign({}, {
NODE_ENV: process.env.NODE_ENV || "development"
}))}),
// Don't run prerender if watching
(watching ? null : new StaticSiteGeneratorPlugin('__prerender', paths))
].filter(plugin => !!plugin),
module: {
loaders: [
JS_LOADER,
JSON_LOADER,
GRAPHQL_LOADER,
FILE_LOADER,
{
test: /\.scss$/,
loaders: ["style-loader?sourceMap", "css-loader?sourceMap", "postcss-loader?sourceMap", "sass-loader?sourceMap"]
}
]
},
postcss: function() {
return [autoprefixer({browsers : ['ie >= 9', 'last 2 versions']})]
},
devServer : {
host: '0.0.0.0',
publicPath : '/',
port: process.env.SEMANTIC_FAUNA_PORT || 3000,
historyApiFallback: true
}
};
const production = Object.assign({}, development, {
devtool: undefined,
cache: false,
output: Object.assign({}, development.output, {
filename: '[name]-[hash].js'
}),
plugins: [
new ExtractTextPlugin('semantic-fauna-[contenthash].css'),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin()
].concat(development.plugins),
module: {
loaders: [
JS_LOADER,
JSON_LOADER,
GRAPHQL_LOADER,
FILE_LOADER,
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("css-loader!postcss-loader!sass-loader")
}
]
},
});
module.exports = process.env.NODE_ENV === 'production' ? production : development;