Skip to content
This repository was archived by the owner on May 19, 2022. It is now read-only.

Commit 3ae5a25

Browse files
authored
Merge pull request #58 from panter/chore/init-rollup
feat: better packaging for distribution
2 parents edd7f3e + 50558bf commit 3ae5a25

File tree

6 files changed

+167
-61
lines changed

6 files changed

+167
-61
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"presets": [["@babel/env", { "modules": "commonjs" }]],
2+
"presets": [["@babel/env"]],
33
"plugins": [
44
"add-module-exports",
55
"@babel/plugin-proposal-object-rest-spread"

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
"vue.js"
2020
],
2121
"scripts": {
22+
"roll": "rollup",
2223
"prepublish": "npm run build",
2324
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
24-
"build": "cross-env webpack --mode=production --progress --hide-modules && npm run build:lib",
25-
"build:lib": "rimraf ./lib && babel src --out-dir lib",
25+
"build": "cross-env NODE_ENV=production rollup -c rollup.config.js",
2626
"lint": "eslint src/**.js",
2727
"test": "npm run lint && npm run test:unit && npm run test:types",
2828
"test:unit": "cross-env BABEL_ENV=test karma start test/karma.conf.js",
@@ -35,7 +35,9 @@
3535
"docs:clean": "rm -rf docs/.vuepress/**",
3636
"docs:build": "vuepress build docs"
3737
},
38-
"main": "./dist/vue-i18next.js",
38+
"main": "./dist/vue-i18next.common.js",
39+
"module": "./dist/vue-i18next.esm.js",
40+
"unpkg": "./dist/vue-i18next.js",
3941
"types": "typings/index.d.ts",
4042
"peerDependencies": {
4143
"i18next": ">= 6.0.1",
@@ -88,12 +90,15 @@
8890
"ncp": "^2.0.0",
8991
"phantomjs-prebuilt": "^2.1.14",
9092
"rimraf": "^2.6.1",
93+
"rollup": "^0.66.0",
94+
"rollup-plugin-buble": "^0.19.2",
95+
"rollup-plugin-commonjs": "^9.1.8",
96+
"rollup-plugin-node-resolve": "^3.4.0",
97+
"rollup-plugin-replace": "^2.0.0",
9198
"semantic-release": "^6.3.6",
9299
"sinon": "^2.1.0",
93100
"sinon-chai": "^2.8.0",
94101
"typescript": "^2.8.3",
95-
"uglifyjs-3-webpack-plugin": "^1.2.4",
96-
"uglifyjs-webpack-plugin": "^2.1.1",
97102
"vue": "^2.5.16",
98103
"vue-class-component": "^6.2.0",
99104
"vue-loader": "^10.0.0",

rollup.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require('path');
2+
const pack = require('./package.json');
3+
const replace = require('rollup-plugin-replace');
4+
// const flow = require('rollup-plugin-flow-no-whitespace');
5+
const buble = require('rollup-plugin-buble');
6+
const node = require('rollup-plugin-node-resolve');
7+
const cjs = require('rollup-plugin-commonjs');
8+
9+
const resolve = _path => path.resolve(__dirname, _path);
10+
const name = 'VueI18next';
11+
const fileName = 'vue-i18next';
12+
const replacePluginOptions = { __VERSION__: `"${pack.version}"` };
13+
14+
const rollupPlugins = () => [
15+
replace(replacePluginOptions),
16+
buble({ objectAssign: 'Object.assign' }),
17+
node(),
18+
cjs(),
19+
];
20+
21+
const conf = (format, formatName) => ({
22+
input: 'src/i18n.js',
23+
plugins: rollupPlugins(),
24+
external: ['deepmerge'],
25+
output: {
26+
file: resolve(`dist/${fileName}${formatName ? `.${formatName}` : ''}.js`),
27+
format,
28+
env: 'production',
29+
name,
30+
},
31+
});
32+
33+
export default [conf('cjs', 'common'), conf('es', 'esm'), { ...conf('umd'), external: [] }];

typings/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"module": "es2015",
44
"moduleResolution": "node",
5+
"target": "es2015",
56
"allowSyntheticDefaultImports": true,
67
"experimentalDecorators": true,
78
"strict": true,

webpack.config.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
const path = require('path');
22
const webpack = require('webpack');
3-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
43
const config = require('./package.json');
54

65
module.exports = {
6+
mode: 'development',
77
entry: './src/i18n.js',
88
output: {
99
path: path.resolve(__dirname, './dist'),
1010
publicPath: '/dist/',
11-
filename: 'vue-i18next.js',
12-
library: ['VueI18next'],
13-
libraryTarget: 'umd',
14-
umdNamedDefine: true,
1511
},
1612
module: {
1713
rules: [
@@ -46,22 +42,3 @@ module.exports = {
4642
},
4743
devtool: '#eval-source-map',
4844
};
49-
50-
// if (process.env.NODE_ENV === 'production') {
51-
module.exports.optimization = {
52-
minimizer: [new UglifyJsPlugin({ sourceMap: true })],
53-
};
54-
55-
module.exports.devtool = '#source-map';
56-
// http://vue-loader.vuejs.org/en/workflow/production.html
57-
module.exports.plugins = (module.exports.plugins || []).concat([
58-
new webpack.DefinePlugin({
59-
'process.env': {
60-
NODE_ENV: '"production"',
61-
},
62-
}),
63-
// new webpack.LoaderOptionsPlugin({
64-
// minimize: true,
65-
// }),
66-
]);
67-
// }

0 commit comments

Comments
 (0)