update build scripts for npm publish
MODIFY
package-lock.json
package-lock.json
}
}
},
- "cross-env": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.2.0.tgz",
- "integrity": "sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg==",
- "dev": true,
- "requires": {
- "cross-spawn": "^6.0.5",
- "is-windows": "^1.0.0"
- }
- },
"cross-spawn": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",

MODIFY
package.json
package.json
"shim:coveralls": "nyc report --reporter=text-lcov | coveralls",
"shim:build": "npm run shim:build:dev && npm run shim:build:prod",
"shim:watch": "npm run shim:build:dev --watch",
- "shim:build:dev": "cross-env NODE_ENV=development rollup -c rollup.config.js",
- "shim:build:prod": "cross-env NODE_ENV=production rollup -c rollup.config.js"
+ "shim:build:dev": "rollup -c",
+ "shim:build:prod": "rollup -c --environment NODE_ENV:production"
},
"devDependencies": {
"coveralls": "^3.0.3",
- "cross-env": "^5.2.0",
"eslint": "^5.15.3",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",

MODIFY
rollup.config.js
rollup.config.js
-import path from 'path';
import minify from 'rollup-plugin-babel-minify';
import stripCode from 'rollup-plugin-strip-code';
+export default () => {
const isProduction = process.env.NODE_ENV === 'production';
+ const minfix = isProduction ? '.min' : '';
-export default {
- input: path.resolve('src/main.js'),
- output: [
+ const output = [
{
- file: path.resolve(isProduction ? 'dist/realms-shim.umd.min.js' : 'dist/realms-shim.umd.js'),
+ file: `dist/realms-shim.umd${minfix}.js`,
name: 'Realm',
format: 'umd',
sourcemap: true
},
{
- file: 'dist/realms-shim.esm.js',
+ file: `dist/realms-shim.esm${minfix}.js`,
format: 'esm',
sourcemap: true
- },
- {
- file: 'dist/realms-shim.cjs.js',
- format: 'cjs',
- sourcemap: true
}
- ],
- plugins: [
+ ];
+
+ const plugins = [
stripCode({
start_comment: 'START_TESTS_ONLY',
end_comment: 'END_TESTS_ONLY'
- }),
- isProduction
- ? minify({
+ })
+ ];
+
+ if (isProduction) {
+ plugins.push(
+ minify({
comments: false
})
- : {}
- ]
+ );
+ } else {
+ output.push({
+ file: 'dist/realms-shim.cjs.js',
+ format: 'cjs',
+ sourcemap: true
+ });
+ }
+
+ return {
+ input: 'src/main.js',
+ output,
+ plugins
};
+}

update build scripts for npm publish