Skip to content

Commit a31efa9

Browse files
committed
chore(build): improve build process
1 parent 364d2df commit a31efa9

File tree

8 files changed

+227
-153
lines changed

8 files changed

+227
-153
lines changed

karma.conf.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@ module.exports = function (config) {
3434
'test/unit/*.spec.js': ['rollup']
3535
},
3636

37-
rollupPreprocessor: {
38-
plugins: require('./rollup.plugins.js'),
39-
output: {
40-
format: 'iife',
41-
name: 'WsTest',
42-
sourcemap: 'inline'
43-
}
44-
},
37+
rollupPreprocessor: require('./test/unit/rollup.config.js'),
4538

4639
// test results reporter to use
4740
// possible values: 'dots', 'progress'

package-lock.json

Lines changed: 17 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"browser": "dist/Ws.browser.js",
88
"scripts": {
99
"lint": "standard",
10-
"build": "rollup -c",
10+
"build": "rollup -c --umd && rollup -c --umd-production && rollup -c --esm",
1111
"prepublishOnly": "npm run build",
1212
"pretest": "npm run lint",
1313
"test:karma": "karma start",
@@ -26,6 +26,7 @@
2626
"babel-cli": "^6.26.0",
2727
"babel-core": "^6.26.0",
2828
"babel-plugin-external-helpers": "^6.22.0",
29+
"babel-plugin-transform-object-assign": "^6.22.0",
2930
"babel-polyfill": "^6.26.0",
3031
"babel-preset-env": "^1.6.1",
3132
"cz-conventional-changelog": "^2.1.0",
@@ -40,22 +41,21 @@
4041
"rollup-plugin-babel": "^3.0.3",
4142
"rollup-plugin-commonjs": "^9.1.0",
4243
"rollup-plugin-node-resolve": "^3.2.0",
43-
"rollup-plugin-strip": "^1.1.1",
44-
"rollup-plugin-strip-code": "^0.2.5",
44+
"rollup-plugin-replace": "^2.0.0",
4545
"rollup-plugin-uglify": "^3.0.0",
4646
"standard": "^11.0.1",
4747
"ws": "^5.0.0"
4848
},
4949
"dependencies": {
5050
"@adonisjs/websocket-packet": "^1.0.6",
5151
"emittery": "^0.3.0",
52-
"extend": "^3.0.1",
5352
"query-string": "^6.0.0"
5453
},
5554
"standard": {
5655
"globals": [
5756
"test",
58-
"group"
57+
"group",
58+
"QUnit"
5959
]
6060
},
6161
"config": {

rollup.config.js

Lines changed: 73 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,94 @@
1-
import pkg from './package.json'
2-
import uglify from 'rollup-plugin-uglify'
3-
import stripCode from 'rollup-plugin-strip-code'
4-
import strip from 'rollup-plugin-strip'
1+
const pkg = require('./package')
2+
const basePlugins = require('./rollup.plugins.js')
53

6-
const plugins = require('./rollup.plugins.js')
7-
8-
const pluginUglify = uglify()
9-
10-
const pluginStripCode = stripCode({
11-
start_comment: 'DEV',
12-
end_comment: 'END_DEV'
4+
const pluginBabel = require('rollup-plugin-babel')({
5+
ignore: /node_modules\/(!emittery).*/,
6+
plugins: ['external-helpers', 'transform-object-assign'],
7+
presets: [
8+
[
9+
'env',
10+
{
11+
modules: false,
12+
targets: {
13+
browsers: ['last 4 versions', 'safari >= 7', 'ie 11']
14+
}
15+
}
16+
]
17+
]
1318
})
1419

15-
const pluginStrip = strip({
16-
functions: ['debug']
17-
})
20+
/**
21+
* UMD build
22+
*
23+
* @method umdBuild
24+
*
25+
* @return {Object}
26+
*/
27+
function umdBuild () {
28+
const pluginReplace = require('rollup-plugin-replace')({
29+
'process.env.NODE_ENV': JSON.stringify('development')
30+
})
1831

19-
export default [
20-
{
32+
return {
2133
input: 'index.js',
2234
output: {
2335
file: pkg.browser,
2436
name: 'adonis.Ws',
2537
format: 'umd'
2638
},
27-
plugins
28-
},
29-
{
39+
plugins: [pluginReplace].concat(basePlugins).concat([pluginBabel])
40+
}
41+
}
42+
43+
/**
44+
* Umd build for production
45+
*
46+
* @method umdProductionBuild
47+
*
48+
* @return {Object}
49+
*/
50+
function umdProductionBuild () {
51+
const pluginReplace = require('rollup-plugin-replace')({
52+
'process.env.NODE_ENV': JSON.stringify('production')
53+
})
54+
55+
const pluginUglify = require('rollup-plugin-uglify')()
56+
57+
return {
3058
input: 'index.js',
3159
output: {
32-
file: `${pkg.browser.replace('.js', '.min.js')}`,
60+
file: `${pkg.browser.replace(/\.js$/, '.min.js')}`,
3361
name: 'adonis.Ws',
3462
format: 'umd'
3563
},
36-
plugins: plugins.concat([pluginStrip, pluginStripCode, pluginUglify])
37-
},
38-
{
64+
plugins: [pluginReplace].concat(basePlugins).concat([pluginBabel, pluginUglify])
65+
}
66+
}
67+
68+
/**
69+
* Es build
70+
*
71+
* @method esBuild
72+
*
73+
* @return {Object}
74+
*/
75+
function esBuild () {
76+
return {
3977
input: 'index.js',
4078
output: {
4179
file: pkg.module,
4280
format: 'es'
4381
},
44-
plugins
45-
},
46-
{
47-
input: 'index.js',
48-
output: {
49-
file: `${pkg.module.replace('.js', '.prod.js')}`,
50-
format: 'es'
51-
},
52-
plugins: plugins.concat([pluginStrip, pluginStripCode])
82+
plugins: basePlugins.concat([pluginBabel])
5383
}
54-
]
84+
}
85+
86+
const build = process.argv.slice(3)[0]
87+
88+
if (build === '--umd') {
89+
module.exports = umdBuild()
90+
} else if (build === '--umd-production') {
91+
module.exports = umdProductionBuild()
92+
} else if (build === '--esm') {
93+
module.exports = esBuild()
94+
}

rollup.plugins.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
'use strict'
2+
3+
/*
4+
* adonis-websocket-client
5+
*
6+
* (c) Harminder Virk <virk@adonisjs.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
/**
13+
* Base plugins
14+
*
15+
* @type {Array}
16+
*/
117
module.exports = [
218
require('rollup-plugin-node-resolve')({
319
main: true,
420
jsnext: true,
521
browser: true
622
}),
7-
require('rollup-plugin-commonjs')(),
8-
require('rollup-plugin-babel')({
9-
exclude: 'node_modules/**',
10-
plugins: ['external-helpers'],
11-
presets: [
12-
[
13-
'env',
14-
{
15-
modules: false,
16-
exclude: ['transform-es2015-classes'],
17-
targets: {
18-
browsers: ['last 4 versions', 'safari >= 7', 'ie 11']
19-
}
20-
}
21-
]
22-
]
23-
})
23+
require('rollup-plugin-commonjs')()
2424
]

0 commit comments

Comments
 (0)