-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
98 lines (88 loc) · 2.27 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
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const dev = (process.env.NODE_ENV !== 'production')
const cssLoaders = [
'css-loader?modules&localIdentName=[path]_[local]__[hash:base64:5]',
'postcss-loader',
'sass-loader',
]
function getEntrySources() {
const entries = []
if (dev) {
entries.push('react-hot-loader/patch')
entries.push('./examples/index-hmr.jsx')
} else {
entries.push('./examples')
}
return entries
}
function getPlugins(plugins) {
plugins.push(new HtmlWebpackPlugin({
template: 'examples/index.html',
inject: true,
hash: true,
}))
plugins.push(new webpack.NamedModulesPlugin())
if (!dev) {
plugins.push(new ExtractTextPlugin('kriya.css'))
}
return plugins
}
module.exports = {
devtool: dev ? 'eval' : '',
entry: { kriya: getEntrySources() },
output: {
path: path.resolve('public'),
filename: '[name].js',
publicPath: dev ? '/' : '/kriya/',
},
resolve: {
modules: [
path.resolve('node_modules'),
path.resolve('./src'),
path.resolve('./examples'),
],
extensions: ['.js', '.jsx', '.scss'],
},
plugins: getPlugins([]),
module: {
rules: [
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'examples'),
],
use: ['babel-loader'],
},
{
test: /global\.scss$/,
include: [
path.resolve(__dirname, 'examples'),
],
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.scss$/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'examples'),
],
exclude: [/global\.scss/],
use: dev ? ['style-loader', ...cssLoaders] : ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: cssLoaders,
}),
},
{
test: [/(ttf|eot|svg|woff)(\?v=[0-9]\.[0-9]\.[0-9])?/],
exclude: [/^\.\.\/\.\.\/resources\/drawings\//],
use: ['file-loader'],
},
],
},
}