-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
211 lines (194 loc) · 5.43 KB
/
gulpfile.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
202
203
204
205
206
207
208
209
210
211
const gulp = require("gulp");
const gutil = require("gulp-util");
const webpack = require("webpack");
const path = require("path");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const WebpackDevServer = require("webpack-dev-server");
function webpackOptions(options) {
let plugins = [];
if (options.stats) {
plugins.push(
new BundleAnalyzerPlugin()
);
}
return {
watch: options.watch,
entry: {
main: './assets/main.js',
},
output: {
path: options.outputPath,
filename: "[name].js",
publicPath: options.publicPath
},
resolve: {
extensions: ['.ts', '.js', '.vue'],
alias: {
'vue$': 'vue/dist/vue.common.js'
}
},
module: {
rules: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, "assets"),
],
exclude: [
path.resolve(__dirname, "assets/build"),
],
loader: 'babel-loader',
options: {
presets: ['es2015'],
plugins: [
"transform-vue-jsx",
"transform-object-rest-spread",
"async-import",
]
}
},
{
test: /\.html/,
use: 'html-loader'
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader?' + JSON.stringify({
presets: ['es2015'],
plugins: [
"transform-vue-jsx",
"transform-object-rest-spread",
"async-import",
]
}),
javascript: 'babel-loader?' + JSON.stringify({
presets: ['es2015'],
plugins: [
"transform-vue-jsx",
"transform-object-rest-spread",
"async-import",
]
}),
scss: "vue-style-loader!style-loader!css-loader!sass-loader",
}
}
},
{
test: /\.(ts|tsx)?$/,
loader: 'awesome-typescript-loader',
options: {
transpileOnly: true
},
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
},
{
test: /\.less$/,
use: [
'style-loader',
{loader: 'css-loader', options: {importLoaders: 1}},
'less-loader'
]
},
{
test: /\.png$/,
use: "url-loader?limit=100000"
},
{
test: /\.jpg$/,
use: "file-loader"
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: "url-loader?limit=10000&minetype=application/font-woff"
},
{
test: /\.(gif|svg|ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: "file-loader"
}
]
},
plugins: plugins
};
}
gulp.task("watch", function() {
webpack(webpackOptions({
watch: true,
debug: true,
publicPath: '/assets/build/',
outputPath: __dirname + "/public/build",
}), function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({}));
});
});
gulp.task("server", function() {
let compiler = webpack(webpackOptions({
watch: false,
debug: true,
publicPath: 'http://localhost:8181/assets/build/',
outputPath: __dirname + "/assets/build",
}), function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({}));
});
const server = new WebpackDevServer(compiler, {
// webpack-dev-server options
contentBase: __dirname + "/assets/build",
watchContentBase: true,
// Can also be an array, or: contentBase: "http://localhost/",
hot: false,
inline: true,
// Enable special support for Hot Module Replacement
// Page is no longer updated, but a "webpackHotUpdate" message is sent to the content
// Use "webpack/hot/dev-server" as additional module in your entry point
// Note: this does _not_ add the `HotModuleReplacementPlugin` like the CLI option does.
// compress: true,
// Set this if you want to enable gzip compression for assets
//
// proxy: {
// "**": "http://localhost:9090"
// },
// webpack-dev-middleware options
// quiet: false,
// noInfo: false,
// lazy: true,
filename: "main.js",
watchOptions: {
aggregateTimeout: 300,
// poll: 1000
},
// It's a required option.
publicPath: "/assets/build/",
stats: {
colors: true
},
});
server.listen(8181, "localhost", (err) => {
if(err) throw new gutil.PluginError("webpack-dev-server", err);
// Server listening
gutil.log("[webpack-dev-server]", "http://localhost:8181/webpack-dev-server/index.html");
});
});
gulp.task("production", function() {
webpack(webpackOptions({
watch: false,
debug: false,
publicPath: '/assets/build/',
outputPath: __dirname + "/public/build",
}), function(err, stats) {
if(err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
// output options
}));
});
});