-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.common.js
89 lines (86 loc) · 2.26 KB
/
webpack.common.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
// import webpack from 'webpack';
// import path from 'path';
// import BundleTracker from 'webpack-bundle-tracker';
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const webpack = require('webpack');
const path = require('path');
const BundleTracker = require('webpack-bundle-tracker');
const BUILD_DIR = path.resolve(__dirname, 'assets/build');
const APP_DIR = path.resolve(__dirname, 'assets/js');
const config = {
context: __dirname,
entry: [
`${APP_DIR}/entry.jsx`
],
output: {
path: BUILD_DIR,
filename: '[name]-[hash].js'
},
module: {
rules: [
{
test: /\.jsx?$/,
include: APP_DIR,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', 'react'],
plugins: []
}
}
},
{
test: /\.ne$/,
loader: 'nearley-loader'
},
{ // scss loader for webpack
test: /\.scss$/,
use: [
// fallback to style-loader in development
process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader"
]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader"
]
},
{
test: /\.styl$/,
loader: 'style!css!stylus'
},
{
test: /\.(mp4|webm|mp3|ogg|wav|jpeg|jpg|bmp|ico|png|gif|ttf|otf|woff|eot)$/,
loader: 'file-loader?name=[path][name].[ext]?[hash]'
}
]
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new BundleTracker({filename: './webpack-stats.json'}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[id].css"
})
]
};
module.exports = config;