Skip to content

Commit 5b794e3

Browse files
author
Ives van Hoorne
committed
Improve builds
1 parent c9847bb commit 5b794e3

File tree

6 files changed

+90
-48
lines changed

6 files changed

+90
-48
lines changed

packages/react-sandpack/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ compiled
22
storybook-static
33
.rpt2_cache
44
dist
5+
es
56
docs
67
.env

packages/react-sandpack/package.json

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"description": "",
55
"keywords": [],
66
"license": "SEE LICENSE.MD IN ROOT",
7-
"main": "dist/react-sandpack.umd.js",
8-
"module": "dist/react-sandpack.es5.js",
7+
"main": "dist/react-sandpack.js",
8+
"browser": "dist/react-sandpack.umd.js",
9+
"module": "es/react-sandpack.js",
10+
"jsnext:main": "es/react-sandpack.js",
911
"typings": "dist/types/react-sandpack.d.ts",
10-
"files": [
11-
"dist"
12-
],
12+
"files": ["dist", "es"],
1313
"author": "Ives van Hoorne <[email protected]>",
1414
"repository": {
1515
"type": "git",
@@ -20,8 +20,10 @@
2020
},
2121
"scripts": {
2222
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
23-
"prebuild": "rimraf dist",
24-
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src && gulp sass",
23+
"prebuild": "rimraf dist && rimraf es",
24+
"build":
25+
"tsc --module commonjs && rollup -c rollup.config.ts && yarn build:min && typedoc --out docs --target es6 --theme minimal --mode file src && gulp build",
26+
"build:min": "cross-env BUILD_MINIFY=1 rollup -c rollup.config.ts",
2527
"start": "npm-run-all --parallel watch:**",
2628
"watch:rollup": "rollup -c rollup.config.ts -w",
2729
"watch:gulp": "gulp sass:watch",
@@ -47,23 +49,17 @@
4749
},
4850
"validate-commit-msg": {
4951
"types": "conventional-commit-types",
50-
"helpMessage": "Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
52+
"helpMessage":
53+
"Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
5154
}
5255
},
5356
"jest": {
5457
"transform": {
5558
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
5659
},
5760
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
58-
"moduleFileExtensions": [
59-
"ts",
60-
"tsx",
61-
"js"
62-
],
63-
"coveragePathIgnorePatterns": [
64-
"/node_modules/",
65-
"/test/"
66-
],
61+
"moduleFileExtensions": ["ts", "tsx", "js"],
62+
"coveragePathIgnorePatterns": ["/node_modules/", "/test/"],
6763
"coverageThreshold": {
6864
"global": {
6965
"branches": 90,
@@ -120,6 +116,7 @@
120116
"rollup-plugin-sass": "^0.6.0",
121117
"rollup-plugin-sourcemaps": "^0.4.2",
122118
"rollup-plugin-typescript2": "^0.11.1",
119+
"rollup-plugin-uglify": "^3.0.0",
123120
"semantic-release": "^12.4.1",
124121
"storybook-addon-jsx": "^5.3.0",
125122
"ts-jest": "^22.0.0",

packages/react-sandpack/rollup.config.ts

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,55 @@ import commonjs from 'rollup-plugin-commonjs';
33
import sourceMaps from 'rollup-plugin-sourcemaps';
44
import camelCase from 'lodash.camelcase';
55
import typescript from 'rollup-plugin-typescript2';
6+
import uglify from 'rollup-plugin-uglify';
67

78
const pkg = require('./package.json');
89

910
const libraryName = 'react-sandpack';
1011

11-
export default {
12-
input: `src/${libraryName}.ts`,
13-
output: [
14-
{ file: pkg.main, name: camelCase(libraryName), format: 'umd' },
15-
{ file: pkg.module, format: 'es' },
16-
],
17-
sourcemap: true,
18-
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
19-
external: [],
20-
watch: {
21-
include: 'src/**',
22-
},
23-
plugins: [
24-
// Compile TypeScript files
25-
typescript({ useTsconfigDeclarationDir: true }),
26-
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
27-
commonjs(),
28-
// Allow node_modules resolution, so you can use 'external' to control
29-
// which external modules to include in the bundle
30-
// https://github.com/rollup/rollup-plugin-node-resolve#usage
31-
resolve(),
32-
33-
// Resolve source maps to the original source
34-
sourceMaps(),
35-
],
36-
};
12+
const minify = !!process.env.BUILD_MINIFY;
13+
14+
function getFileName(name) {
15+
if (minify) {
16+
return name.replace('.js', '.min.js');
17+
}
18+
19+
return name;
20+
}
21+
22+
function getConfig({ isUMD }) {
23+
return {
24+
input: `src/${libraryName}.ts`,
25+
output: [
26+
isUMD
27+
? {
28+
file: getFileName(pkg.browser),
29+
name: camelCase(libraryName),
30+
format: 'umd',
31+
}
32+
: { file: getFileName(pkg.main), format: 'cjs' },
33+
],
34+
sourcemap: true,
35+
watch: {
36+
include: 'src/**',
37+
},
38+
external: isUMD ? ['react'] : id => id === 'react' || /codemirror/.test(id),
39+
plugins: [
40+
// Compile TypeScript files
41+
typescript({ useTsconfigDeclarationDir: true }),
42+
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
43+
isUMD && commonjs(),
44+
// Allow node_modules resolution, so you can use 'external' to control
45+
// which external modules to include in the bundle
46+
// https://github.com/rollup/rollup-plugin-node-resolve#usage
47+
isUMD && resolve(),
48+
49+
// Resolve source maps to the original source
50+
sourceMaps(),
51+
52+
minify && uglify(),
53+
],
54+
};
55+
}
56+
57+
export default [getConfig({ isUMD: false }), getConfig({ isUMD: true })];
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
import Preview from './components/Preview/index';
2-
import OpenInCodeSandbox from './components/OpenInCodeSandbox/index';
1+
import BrowserPreview from './components/BrowserPreview';
2+
import CodeMirror from './components/CodeEditor/CodeMirror';
3+
import FileExplorer from './components/FileExplorer';
4+
import Navigator from './components/Navigator';
5+
import OpenInCodeSandbox from './components/OpenInCodeSandbox';
6+
import Preview from './components/Preview';
7+
import SandpackConsumer from './components/SandpackConsumer';
8+
import SandpackProvider from './components/SandpackProvider';
9+
import TranspiledCodeView from './components/TranspiledCodeView';
310

4-
export { Preview, OpenInCodeSandbox };
11+
export {
12+
BrowserPreview,
13+
CodeMirror,
14+
FileExplorer,
15+
Navigator,
16+
OpenInCodeSandbox,
17+
Preview,
18+
SandpackConsumer,
19+
SandpackProvider,
20+
TranspiledCodeView,
21+
};

packages/react-sandpack/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"experimentalDecorators": true,
1212
"emitDecoratorMetadata": true,
1313
"declarationDir": "dist/types",
14-
"outDir": "dist/lib",
14+
"outDir": "es",
1515
"typeRoots": ["node_modules/@types"],
1616
"jsx": "react"
1717
},

yarn.lock

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15908,6 +15908,12 @@ rollup-plugin-typescript2@^0.11.1:
1590815908
rollup-pluginutils "^2.0.1"
1590915909
tslib "^1.9.0"
1591015910

15911+
rollup-plugin-uglify@^3.0.0:
15912+
version "3.0.0"
15913+
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-3.0.0.tgz#a34eca24617709c6bf1778e9653baafa06099b86"
15914+
dependencies:
15915+
uglify-es "^3.3.7"
15916+
1591115917
"rollup-pluginutils@>= 1.3.1", rollup-pluginutils@^2.0.1:
1591215918
version "2.0.1"
1591315919
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.0.1.tgz#7ec95b3573f6543a46a6461bd9a7c544525d0fc0"
@@ -18075,7 +18081,7 @@ uglify-es@^3.1.3:
1807518081
commander "~2.11.0"
1807618082
source-map "~0.6.1"
1807718083

18078-
uglify-es@^3.3.4:
18084+
uglify-es@^3.3.4, uglify-es@^3.3.7:
1807918085
version "3.3.9"
1808018086
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"
1808118087
dependencies:

0 commit comments

Comments
 (0)