Skip to content

Commit 2d5b2df

Browse files
guillaumevincentzenorocha
authored andcommitted
Migrate from Browserify to Webpack (#372)
* Migrate from Browserify to Webpack close #371 Author: Guillaume Vincent <guillaume@oslab.fr> * remove browserify and associated modules and update tests
1 parent 0c3bce2 commit 2d5b2df

3 files changed

Lines changed: 69 additions & 35 deletions

File tree

karma.conf.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
module.exports = function(karma) {
1+
var webpackConfig = require('./webpack.config.js');
2+
3+
module.exports = function (karma) {
24
karma.set({
3-
plugins: ['karma-browserify', 'karma-chai', 'karma-sinon', 'karma-mocha', 'karma-phantomjs-launcher'],
5+
plugins: ['karma-webpack', 'karma-chai', 'karma-sinon', 'karma-mocha', 'karma-phantomjs-launcher'],
46

5-
frameworks: ['browserify', 'chai', 'sinon', 'mocha'],
7+
frameworks: ['chai', 'sinon', 'mocha'],
68

79
files: [
810
'src/**/*.js',
911
'test/**/*.js',
1012
'./node_modules/phantomjs-polyfill/bind-polyfill.js'
1113
],
1214

13-
exclude: ['test/module-systems.js'],
14-
1515
preprocessors: {
16-
'src/**/*.js' : ['browserify'],
17-
'test/**/*.js': ['browserify']
16+
'src/**/*.js': ['webpack'],
17+
'test/**/*.js': ['webpack']
18+
},
19+
20+
webpack: {
21+
module: webpackConfig.module,
22+
plugins: webpackConfig.plugins
1823
},
1924

20-
browserify: {
21-
debug: true,
22-
transform: ['babelify']
25+
webpackMiddleware: {
26+
stats: 'errors-only'
2327
},
2428

2529
browsers: ['PhantomJS']
2630
});
27-
}
31+
};

package.json

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Modern copy to clipboard. No Flash. Just 2kb",
55
"repository": "zenorocha/clipboard.js",
66
"license": "MIT",
7-
"main": "lib/clipboard.js",
7+
"main": "dist/clipboard.js",
8+
"module": "src/clipboard.js",
89
"keywords": [
910
"clipboard",
1011
"copy",
@@ -16,33 +17,30 @@
1617
"tiny-emitter": "^2.0.0"
1718
},
1819
"devDependencies": {
19-
"babel-cli": "^6.24.1",
20-
"babel-core": "^6.24.1",
21-
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
22-
"babel-preset-es2015": "^6.24.1",
23-
"babelify": "^7.3.0",
24-
"bannerify": "Vekat/bannerify#feature-option",
25-
"browserify": "^14.3.0",
26-
"chai": "^3.5.0",
27-
"install": "^0.9.6",
28-
"karma": "^1.6.0",
29-
"karma-browserify": "^5.1.1",
20+
"babel-cli": "^6.5.1",
21+
"babel-core": "^6.5.2",
22+
"babel-loader": "^6.2.10",
23+
"babel-plugin-transform-es2015-modules-umd": "^6.5.0",
24+
"babel-preset-es2015": "^6.5.0",
25+
"chai": "^3.4.1",
26+
"cross-env": "^3.1.4",
27+
"karma": "^1.3.0",
3028
"karma-chai": "^0.1.0",
31-
"karma-mocha": "^1.3.0",
32-
"karma-phantomjs-launcher": "^1.0.4",
33-
"karma-sinon": "^1.0.5",
34-
"mocha": "^3.3.0",
35-
"phantomjs-prebuilt": "^2.1.14",
36-
"sinon": "^2.2.0",
37-
"uglify-js": "^2.8.22",
38-
"watchify": "^3.9.0"
29+
"karma-mocha": "^1.2.0",
30+
"karma-phantomjs-launcher": "^1.0.0",
31+
"karma-sinon": "^1.0.4",
32+
"karma-webpack": "^2.0.2",
33+
"mocha": "^3.1.2",
34+
"phantomjs-prebuilt": "^2.1.4",
35+
"sinon": "^1.17.2",
36+
"webpack": "^2.2.1"
3937
},
4038
"scripts": {
4139
"build": "npm run build-debug && npm run build-min",
42-
"build-debug": "browserify src/clipboard.js -s Clipboard -t [babelify] -p [bannerify --file .banner ] -o dist/clipboard.js",
43-
"build-min": "uglifyjs dist/clipboard.js --comments '/!/' -m screw_ie8=true -c screw_ie8=true,unused=false -o dist/clipboard.min.js",
44-
"build-watch": "watchify src/clipboard.js -s Clipboard -t [babelify] -o dist/clipboard.js -v",
40+
"build-debug": "webpack",
41+
"build-min": "cross-env NODE_ENV=production webpack --optimize-minimize",
42+
"build-watch": "webpack --watch",
4543
"test": "karma start --single-run",
46-
"prepublish": "babel src --out-dir lib"
44+
"prepublish": "npm run build"
4745
}
4846
}

webpack.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var path = require('path');
2+
var webpack = require('webpack');
3+
4+
var production = process.env.NODE_ENV === 'production' || false;
5+
6+
module.exports = {
7+
entry: './src/clipboard.js',
8+
output: {
9+
filename: production ? 'clipboard.min.js' : 'clipboard.js',
10+
path: path.resolve(__dirname, 'dist'),
11+
library: 'Clipboard',
12+
libraryTarget: 'umd'
13+
},
14+
module: {
15+
rules: [
16+
{test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"}
17+
]
18+
},
19+
plugins: production ? [
20+
new webpack.optimize.UglifyJsPlugin({
21+
beautify: false,
22+
mangle: {
23+
screw_ie8: true,
24+
keep_fnames: true
25+
},
26+
compress: {
27+
screw_ie8: true
28+
},
29+
comments: false
30+
})
31+
] : []
32+
};

0 commit comments

Comments
 (0)