-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
120 lines (105 loc) · 2.92 KB
/
webpack.config.js
File metadata and controls
120 lines (105 loc) · 2.92 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
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const fs = require('fs');
const path = require('path');
const autoprefixer = require('autoprefixer');
const assetsPath = path.join(__dirname, '/public');
const config = {
entry: './src/js/index.js',
output: {
path: assetsPath,
publicPath: '/',
filename: '[name].js'
},
resolve: {
modulesDirectories: ['node_modules'],
extensions: ['', '.js', '.jsx', '.less']
},
resolveLoader: {
modulesDirectories: ['node_modules'],
moduleTemplates: ['*-loader', '*'],
extensions: ['', '.js']
},
module: {
preLoaders: [],
loaders: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
plugins: ['transform-runtime', 'transform-object-rest-spread']
}
}, {
test: /\.(jpg|jpeg|png|svg|ttf|eot|woff|woff2)$/,
loader: 'file?name=[path][name].[ext]?[hash]'
}, {
test: /\.json$/, loader: 'json-loader'
}]
},
postcss: () => [autoprefixer({
browsers: ['last 2 versions']
})],
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
_: 'lodash',
React: 'react',
ReactDOM: 'react-dom'
})
],
devServer: {
host: 'localhost', // default
port: 8080, // default
contentBase: assetsPath,
headers: {
'Access-Control-Allow-Origin': '*'
}
}
};
// ESlint
if (fs.existsSync('.eslintrc')) {
config.module.eslint = {
configFile: '.eslintrc'
};
config.module.preLoaders.push({
test: /\.(js|jsx)$/,
loaders: ['eslint'],
include: [path.resolve(__dirname, 'src/js')],
});
}
// Style loaders
if (process.env.production) {
config.output.publicPath = './';
config.module.loaders.push({
test: /\.less$/,
loader: ExtractTextPlugin.extract('css!postcss!less?resolve url')
}/*, {
test: /\.css$/,
loader: ExtractTextPlugin.extract('css?resolve url')
},*/);
} else {
fs.readdirSync(assetsPath)
.map(fileName => path.extname(fileName) === '.css' ? fs.unlinkSync(`${assetsPath}/${fileName}`) : '');
config.module.loaders.push({
test: /\.less$/,
loader: 'style!css!postcss!less?resolve url'
});
}
// Plugins
if (process.env.production) {
config.plugins.push(
new ExtractTextPlugin('[name].css', {
allChunks: true
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
unsafe: true
}
})
);
}
module.exports = config;