Skip to content

Commit 97373da

Browse files
committed
chore(webpack): added uglify to webpack and separated the webpack dev and build configurations.
1 parent ef6b391 commit 97373da

3 files changed

Lines changed: 66 additions & 57 deletions

File tree

Gruntfile.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function(grunt) {
2525
// (call 'grunt watch')
2626
watch: {
2727
files: ['src/**/*'],
28-
tasks: ['dev']
28+
tasks: ['webpack:build-dev', 'copy']
2929
},
3030

3131
copy: {
@@ -55,9 +55,38 @@ module.exports = function(grunt) {
5555

5656
webpack: {
5757
options: webpackConfig,
58+
"build": {
59+
debug: true,
60+
plugins: webpackConfig.plugins.concat(
61+
new webpack.optimize.UglifyJsPlugin({
62+
compress: {
63+
drop_console: true
64+
},
65+
sourceMap: true
66+
}),
67+
new webpack.BannerPlugin("<%= meta.banner %>", {
68+
raw: true
69+
})
70+
)
71+
},
5872
"build-dev": {
73+
devtool: "sourcemap",
5974
debug: true
6075
}
76+
},
77+
78+
'webpack-dev-server': {
79+
options: {
80+
webpack: webpackConfig,
81+
publicPath: '/' + webpackConfig.output.publicPath
82+
},
83+
start: {
84+
keepAlive: true,
85+
webpack: {
86+
devtool: "sourcemap",
87+
debug: true
88+
}
89+
}
6190
}
6291
});
6392

@@ -67,7 +96,7 @@ module.exports = function(grunt) {
6796
grunt.loadNpmTasks("grunt-contrib-clean");
6897
grunt.loadNpmTasks("grunt-webpack");
6998

70-
grunt.registerTask("dev",["clean","webpack:build-dev","copy"]);
71-
grunt.registerTask("build", ["clean", "webpack:build-dev","postcss", "copy"]);
72-
grunt.registerTask("default", ["dev", "watch"]);
99+
grunt.registerTask("serve", ["webpack-dev-server:start"])
100+
grunt.registerTask("default", ["clean", "webpack:build-dev", "copy","watch"]);
101+
grunt.registerTask("build", ["clean", "webpack:build-dev", "postcss", "copy"]);
73102
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "embed-js",
3+
"version": "3.0.0",
34
"description": "A jQuery plugin that analyses the string and automatically embeds emojis, media, maps, tweets, code and services.",
45
"keywords": [
56
"jquery-plugin",
@@ -37,6 +38,7 @@
3738
"babel": "^5.8.23",
3839
"babel-core": "^5.8.25",
3940
"babel-loader": "^5.3.2",
41+
"babel-runtime": "^5.8.25",
4042
"chai": "^3.2.0",
4143
"commitizen": "^1.0.4",
4244
"cssnano": "^2.6.1",

webpack.config.js

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,35 @@
1-
var path = require('path');
1+
var path = require('path');
22
var webpack = require('webpack');
3-
var pkg = require('./package.json');
4-
5-
var banner = "/*\n" +
6-
" * " + pkg.name + " - v" + pkg.version + "\n" +
7-
" * " + pkg.description + "\n" +
8-
" * " + pkg.homepage + "\n" +
9-
" *\n" +
10-
" * Made by " + pkg.author.name + "\n" +
11-
" * Under " + pkg.license + " License\n" +
12-
" */\n";
3+
var pkg = require('./package.json');
134

145
module.exports = {
15-
entry : './src/embed.es6',
16-
output : {
17-
path : path.join(__dirname, 'dist'),
18-
filename: 'embed.js'
19-
},
20-
module : {
21-
preLoaders: [
22-
{
23-
test : /\.es6$/,
24-
exclude: /node_modules/,
25-
loader : 'jshint-loader'
26-
}
27-
],
28-
loaders : [
29-
{
30-
test : /\.es6$/,
31-
exclude: /node_modules/,
32-
loader : 'babel-loader'
33-
}
34-
]
35-
},
36-
plugins: [
37-
// Avoid publishing files when compilation failed
38-
new webpack.NoErrorsPlugin(),
39-
new webpack.ProvidePlugin({
40-
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
41-
}),
42-
43-
new webpack.optimize.UglifyJsPlugin({
44-
compress: {
45-
drop_console: true
46-
}
47-
}),
48-
new webpack.BannerPlugin(banner, {
49-
raw: true
50-
})
51-
],
52-
stats : {
53-
// Nice colored output
54-
colors: true
55-
},
56-
devtool: 'source-map'
6+
entry: './src/embed.es6',
7+
output: {
8+
path: path.join(__dirname, 'dist'),
9+
filename: 'embed.js',
10+
publicPath: 'dist/'
11+
},
12+
module: {
13+
preLoaders: [{
14+
test: /\.es6$/,
15+
exclude: /node_modules/,
16+
loader: 'jshint-loader'
17+
}],
18+
loaders: [{
19+
test: /\.es6$/,
20+
exclude: /node_modules/,
21+
loader: 'babel-loader'
22+
}]
23+
},
24+
plugins: [
25+
// Avoid publishing files when compilation failed
26+
new webpack.NoErrorsPlugin(),
27+
new webpack.ProvidePlugin({
28+
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
29+
})
30+
],
31+
stats: {
32+
// Nice colored output
33+
colors: true
34+
}
5735
};

0 commit comments

Comments
 (0)