-
Notifications
You must be signed in to change notification settings - Fork 38
/
webpack.config.js
201 lines (197 loc) · 5.95 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const webpack = require('webpack');
const path = require('path');
require('babel-polyfill');
const autoprefixer = require('autoprefixer');
const getDefaultBabelConfig = require("webpackcc/lib/getBabelDefaultConfig");
// const bootstrapEntryPoints = require('./webpack.bootstrap.config.js');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
//bootstrap configuration for webpack
const customFile = path.join(__dirname,"bootstrap/.bootstraprc");
// console.log(`=> bootstrap-loader configuration: ${bootstrapEntryPoints.dev}`);
// { dev: 'bootstrap-loader',
// prod: 'bootstrap-loader/extractStyles'
// }
//This is default
module.exports = {
entry: [
'webpack-hot-middleware/client',
'tether',
//https://github.com/HubSpot/tether
//http://tether.io/
'font-awesome-loader',
// bootstrapEntryPoints.dev,
`bootstrap-loader`,
// `bootstrap-loader/lib/bootstrap.loader?extractStyles&configFilePath=${customFile}!bootstrap-loader/no-op.js`,
//将bootstrap的配置添加到webpack的entry中
'./src/client.js',
],
output: {
path: path.join(__dirname, 'public', 'assets'),
filename: '[name]-[hash].js',
publicPath: '/assets/',
},
// devtool: '#cheap-module-eval-source-map',
resolve: { extensions: ['*', '.js'] },
module: {
rules: [
{
test: /\.js$/,
// exclude: function(path){
// var isNpmModule=!!path.match(/node_modules/);
// return isNpmModule;
// },
exclude :path.resolve("node_modules"),
//exclude node_modules folder, or we can use include config to include some path
use: [{
loader: require.resolve("babel-loader"),
options:getDefaultBabelConfig.getDefaultBabel()
}]
},
{
test: /\.jsx$/,
exclude :path.resolve("node_modules"),
// exclude: function(path){
// var isNpmModule=!!path.match(/node_modules/);
// return isNpmModule;
// },
//exclude node_modules folder, or we can use include config to include some path
use: [{
loader:require.resolve('babel-loader'),
options:getDefaultBabelConfig.getDefaultBabel()
}]
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true,
modules: true,
sourceMap: 'inline',
importLoaders: 1,
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
{
loader:'less-loader',
options:{
sourceMap: 'inline'
}
}
],
}),
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true,
modules: true,
sourceMap: 'inline',
importLoaders: 1,
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
{
loader:'less-loader',
options:{
sourceMap: 'inline'
}
}
],
}),
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader:"style-loader",
options:{
}
},
{
loader: 'css-loader',
options: {
minimize: true,
modules: true,
importLoaders: 3,
sourceMap: 'inline',
localIdentName: '[name]__[local]__[hash:base64:5]'
},
},
{
loader:"postcss-loader",
options:{
sourceMap:true
}
},
{
loader:'sass-loader',
options:{
sourceMap: 'inline'
}
}
// {
// loader: 'sass-resources-loader',
// options: {
// // resources: './app/assets/styles/app-variables.scss'
// }
// }
],
}),
},
{
test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'url-loader?limit=10000',
},
{
test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
use: 'file-loader',
},
// Bootstrap 4
{ test: /bootstrap\/dist\/js\/umd\//, loader: 'imports-loader?jQuery=jquery' }
// Bootstrap 3
// { test: /bootstrap-sass\/assets\/javascripts\//, use: 'imports-loader?jQuery=jquery' },
],
},
plugins: [
new ExtractTextPlugin({filename:"common.css"}),
new ExtractTextPlugin({filename:"common1.css"}),
new ExtractTextPlugin({filename:"common2.css"}),
new ExtractTextPlugin({filename:"common3.css"}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
//Do not forget in bootstrap version 4
//You can use expose-loader+ProviderPlugin to expose global variables
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
Tether: "tether",
"window.Tether": "tether",
Alert: "exports-loader?Alert!bootstrap/js/dist/alert",
Button: "exports-loader?Button!bootstrap/js/dist/button",
Carousel: "exports-loader?Carousel!bootstrap/js/dist/carousel",
Collapse: "exports-loader?Collapse!bootstrap/js/dist/collapse",
Dropdown: "exports-loader?Dropdown!bootstrap/js/dist/dropdown",
Modal: "exports-loader?Modal!bootstrap/js/dist/modal",
Popover: "exports-loader?Popover!bootstrap/js/dist/popover",
Scrollspy: "exports-loader?Scrollspy!bootstrap/js/dist/scrollspy",
Tab: "exports-loader?Tab!bootstrap/js/dist/tab",
Tooltip: "exports-loader?Tooltip!bootstrap/js/dist/tooltip",
Util: "exports-loader?Util!bootstrap/js/dist/util"
}),
new webpack.LoaderOptionsPlugin({
postcss: [autoprefixer],
}),
]
};