Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm updates #3

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"polyfill": false,
"regenerator": true
}]
]
}
],
"sourceMaps": true
}
3 changes: 1 addition & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ module.exports = function (karma) {
entry: ['./index.js'],
devtool: 'inline-source-map',
module: {
loaders: [
rules: [
{ test: /\.js$/, exclude: /node_modules|dist/, loader: 'babel-loader' },
{ test: /\.json$/, loader: 'json-loader' }
],
noParse: [
/sinon/
Expand Down
43 changes: 24 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@
"schemas"
],
"dependencies": {
"asn1.js": "^4.9.0",
"asn1.js": "4.9.2",
"tweetnacl": "^1.0.0"
},
"devDependencies": {
"ajv": "^5.3.0",
"ajv": "^6.5.2",
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-loader": "^7.1.5",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.9.0",
"babel-runtime": "^6.26.0",
"babelify": "^8.0.0",
"brfs": "^1.4.3",
"chai": "^4.1.2",
"codecov": "^3.0.0",
"codecov": "^3.0.4",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.11.0",
"eslint-config-standard": "^10.2.1",
Expand All @@ -41,28 +39,35 @@
"husky": "^0.14.3",
"interledger-jsdoc-template": "^2.0.0",
"jsdoc": "^3.5.5",
"json-loader": "^0.5.7",
"karma": "^1.7.1",
"karma": "^3.0.0",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.6",
"karma-webpack": "^4.0.0-beta.0",
"md-toc-filter": "^0.9.0",
"mocha": "^4.0.1",
"mustache": "^2.3.0",
"nyc": "^11.3.0",
"mocha": "^5.2.0",
"nyc": "^12.0.2",
"phantomjs-prebuilt": "^2.1.16",
"readme-to-test": "github:justmoon/readme-to-test#feature/st-improvements",
"release-it": "^5.0.0",
"sinon": "^4.1.2",
"watchify": "^3.9.0",
"webpack": "^3.8.1"
"release-it": "^7.5.0",
"rimraf": "^2.6.2",
"sinon": "^6.1.5",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.16.1",
"webpack-cli": "^3.0.8",
"webpack-concat-plugin": "^3.0.0",
"webpack-merge": "^4.1.3",
"webpack-sources": "^1.1.0"
},
"scripts": {
"lint": "eslint .",
"build": "npm run build:web",
"build": "npm run clean && npm run build:cjs && npm run build:dist",
"build:web": "webpack -p --config webpack.config.js",
"prepublish": "npm run build:web",
"build:bundle": "webpack",
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
"build:dist": "cross-env NODE_ENV=production webpack",
"clean": "rimraf dist/bundle dist/node",
"test:readme": "readme-to-test",
"test:specs": "NODE_ENV=unit nyc mocha",
"test:phantom": "karma start --single-run",
Expand Down
31 changes: 31 additions & 0 deletions plugins/add-vendors-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { ConcatSource } = require('webpack-sources')

module.exports = class AddVendorsPlugin {
constructor(base) {
this.base = base
}

apply(compiler) {
compiler.hooks.emit.tapAsync(
`AddVendorsPlugin ${this.base}`,
(compilation, callback) => {
const main = compilation.assets[`main.${this.base}`]
const mainMap = compilation.assets[`main.${this.base}.map`]
const vendor = compilation.assets[`vendors.${this.base}`]

if (main && vendor) {
const compiledAsset = new ConcatSource(main.children[0])
compiledAsset.add(vendor)
compiledAsset.add(main.children[1])
compilation.assets = {}
compilation.assets[this.base] = compiledAsset
} else if (main && mainMap) {
compilation.assets = {}
compilation.assets[this.base] = main
compilation.assets[`${this.base}.map`] = mainMap
}
callback()
}
)
}
}
29 changes: 29 additions & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable strict, no-console, object-shorthand */

'use strict'

const { paths } = require('./webpack.parts.js')

module.exports = {
entry: paths.entry,
mode: 'none',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
}
]
},
optimization: {
minimize: true,
noEmitOnErrors: true
},
resolve: {
extensions: ['.js'],
modules: ['node_modules'],
},
}
67 changes: 31 additions & 36 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
const webpack = require('webpack')
const path = require('path')
/* eslint-disable strict, no-console, object-shorthand */

module.exports = {
devtool: '#source-map',
entry: ['./index.js'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js',
library: 'CryptoConditions',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.json$/, loader: 'json-loader' }
]
},
node: {
fs: 'empty'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: true
}),
new webpack.LoaderOptionsPlugin({
debug: false,
minimize: true
})
]
'use strict'

const PRODUCTION = process.env.NODE_ENV === 'production'

const common = require('./webpack.common.js')

const { outputs } = require('./webpack.parts.js')

// '[libraryTarget]': [file extension]
const OUTPUT_MAPPING = {
'amd': 'amd',
'commonjs': 'cjs',
'commonjs2': 'cjs2',
'umd': 'umd',
'window': 'window',
}

const OVERRIDES = {
// optimization: {
// minimize: false
// }
node: {
fs: "empty"
}
}

if (PRODUCTION) {
module.exports = outputs(common, 'production', OUTPUT_MAPPING, OVERRIDES)
} else {
module.exports = outputs(common, 'development', OUTPUT_MAPPING, OVERRIDES)
}
30 changes: 30 additions & 0 deletions webpack.development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable strict, no-console, object-shorthand */

'use strict'

const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
devtool: 'inline-source-map',
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /vendor/,
sourceMap: false,
}),
new UglifyJsPlugin({
test: /^((?!(vendor)).)*.js$/,
sourceMap: true,
})
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
},
},
}
55 changes: 55 additions & 0 deletions webpack.parts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable strict, no-console, object-shorthand */

'use strict'

const path = require('path')
const merge = require('webpack-merge')

const development = require('./webpack.development.js')
const production = require('./webpack.production.js')

const AddVendorsPlugin = require('./plugins/add-vendors-plugin')

const paths = {
entry: path.resolve(__dirname, './index.js'),
bundle: path.resolve(__dirname, 'dist/browser'),
}

const outputs = (base, env, mapping, overrides) => {
const collection = []
const library = 'CryptoConditions'
const windowLibrary = 'CryptoConditions'

let environment = development
let ext = 'js'

if (env === 'production') {
environment = production
ext = `min.${ext}`
}

Object.entries(mapping).forEach(([target, extension]) => {
const filename = `[name].${library}.${extension}.${ext}`

const compiled = {
output: {
filename: filename,
library: target === 'window' ? windowLibrary : library,
libraryTarget: target,
path: paths.bundle
},
plugins: [
new AddVendorsPlugin(`${library}.${extension}.${ext}`)
]
}

collection.push(merge(base, environment, compiled, overrides))
})

return collection
}

module.exports = {
outputs,
paths
}
7 changes: 7 additions & 0 deletions webpack.production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable strict, no-console, object-shorthand */

'use strict'

module.exports = {
devtool: 'source-map',
}