Skip to content

Commit

Permalink
fix(webpack): Update modules and webpack config, add test case for st…
Browse files Browse the repository at this point in the history
…ring with vars
  • Loading branch information
kevinchappell committed Aug 13, 2018
1 parent 0318e10 commit 7766316
Show file tree
Hide file tree
Showing 5 changed files with 866 additions and 1,027 deletions.
45 changes: 24 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"description": "A simple yet robust i18n solution for universal JavaScript apps.",
"main": "dist/mi18n.min.js",
"scripts": {
"test": "node node_modules/mocha/bin/mocha --compilers js:babel-core/register src/**/*.test.js",
"test": "node node_modules/mocha/bin/mocha --require babel-core/register src/**/*.test.js",
"test:watch": "yarn test -- --reporter min --watch",
"build": "rm -rf dist/ && webpack -p --progress --colors",
"start": "webpack-dev-server -d",
"tag": "babel-node --no-babel-rc --presets=es2015 tools/run tag",
"build": "rm -rf dist/ && webpack --mode production --progress",
"start": "webpack-dev-server --mode development",
"semantic-release": "semantic-release",
"travis-deploy-once": "travis-deploy-once"
},
"engines": {
"node": ">=9.10.0"
},
"repository": {
"url": "https://github.com/Draggable/mi18n",
"type": "git"
Expand Down Expand Up @@ -49,27 +51,28 @@
},
"devDependencies": {
"axios": "^0.18.0",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.0.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-loader": "^7.1.5",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.4.0",
"chai": "^3.5.0",
"compression-webpack-plugin": "^0.4.0",
"eslint": "^3.19.0",
"eslint-config-google": "^0.7.1",
"eslint-config-prettier": "^2.9.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-prettier": "^2.6.0",
"babel-preset-env": "^1.7.0",
"chai": "^4.1.2",
"compression-webpack-plugin": "^1.1.11",
"eslint": "^5.3.0",
"eslint-config-google": "^0.9.1",
"eslint-config-prettier": "^3.0.1",
"eslint-loader": "^2.1.0",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-prettier": "^2.6.2",
"json-update": "^3.0.0",
"mocha": "^3.2.0",
"replace-in-file": "^2.5.0",
"mocha": "^5.2.0",
"replace-in-file": "^3.4.0",
"semantic-release": "^15.9.8",
"webpack": "^2.4.1",
"webpack-dev-server": "^2.4.4",
"travis-deploy-once": "^5.0.2"
"travis-deploy-once": "^5.0.2",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
},
"eslintConfig": {
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions src/mi18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class I18N {
if (!value) {
return
}
const tokens = value.match(/\{[^\}]+?\}/g)
const tokens = value.match(/\{[^}]+?\}/g)
let token

if (args && tokens) {
Expand All @@ -122,7 +122,7 @@ export class I18N {
value = value.replace(_this.makeSafe(tokens[i]), args[token] || '')
}
} else {
value = value.replace(/\{[^\}]+?\}/g, args)
value = value.replace(/\{[^}]+?\}/g, args)
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/mi18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('I18N', () => {
override: {
'te-ST': {
testKey: 'Teeesst',
testVars: 'I saw {count} {animals}',
},
},
}
Expand Down Expand Up @@ -44,6 +45,14 @@ describe('I18N', () => {
const str = mi18n.get('testKey')
expect(str).to.equal('Teeesst')
})

it('shall return a string with vars', () => {
const str = mi18n.get('testVars', {
count: 3,
animals: 'chickens'
})
expect(str).to.equal('I saw 3 chickens')
})
})
})
})
Expand Down
6 changes: 4 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { BannerPlugin } = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
const MinifyPlugin = require('babel-minify-webpack-plugin')

const PRODUCTION = process.argv.includes('-p')
const PRODUCTION = process.argv.includes('production')

const bannerTemplate = [`${pkg.name} - ${pkg.homepage}`, `Version: ${pkg.version}`, `Author: ${pkg.author}`].join('\n')

Expand All @@ -27,9 +27,11 @@ const plugins = [
}),
]

const devtool = PRODUCTION ? false : 'source-map'
const devtool = PRODUCTION ? false : 'inline-source-map'

const webpackConfig = {
mode: PRODUCTION ? 'production' : 'development',
context: resolve(__dirname),
entry: {
mi18n: './src/mi18n.js',
},
Expand Down
Loading

0 comments on commit 7766316

Please sign in to comment.