Skip to content

Commit 0d9c325

Browse files
update package.json script
1 parent 9e0ad7b commit 0d9c325

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rollup*
1313

1414
#development
1515
/build
16+
/sandbox
1617

1718
#demo
1819
/example

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
},
1717
"scripts": {
1818
"watch": "set NODE_OPTIONS=--openssl-legacy-provider & cross-env BABEL_OUTPUT=umd INCLUDE_POLYFILLS=true webpack --config webpack.config.js --env=development --watch",
19-
"build": "set NODE_OPTIONS=--openssl-legacy-provider & npm-run-all clean:* --parallel build:lib:* & npm-run-all --parallel build:umd:*",
20-
"build:umd:dev": "cross-env BABEL_OUTPUT=umd INCLUDE_POLYFILLS=true webpack --config webpack.config.js --env=development",
21-
"build:umd:prod": "rollup -c",
22-
"build:umd:prod-pf": "cross-env INCLUDE_POLYFILLS=true rollup -c",
19+
"build": "set NODE_OPTIONS=--openssl-legacy-provider & npm-run-all clean:* --parallel build:lib:* & npm run build:dist",
20+
"build:dist": "rollup -c",
2321
"build:lib:cjs": "cross-env BABEL_OUTPUT=cjs babel src/ --out-dir lib/cjs/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
2422
"build:lib:esm": "babel src/ --out-dir lib/esm/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
2523
"build:lib:esm-pf": "cross-env INCLUDE_POLYFILLS=true babel src/ --out-dir lib/esm-including-polyfills/ --ignore **/__tests__,**/__mocks__,**/*.test.js,**/*.js.snap",
@@ -68,11 +66,17 @@
6866
"webpack-cli": "^3.3.12"
6967
},
7068
"files": [
69+
"plugins",
7170
"dist",
71+
"flow-typed",
7272
"lib",
73+
"style",
74+
"theme",
75+
"themes",
7376
"src",
7477
"!*.test.js",
75-
"!*.test.js.snap"
78+
"!*.test.js.snap",
79+
"index.d.ts"
7680
],
7781
"keywords": [
7882
"react",

rollup.config.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,37 @@ const name = pkg.name
66
.split('-')
77
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
88
.join('');
9-
const requirePolyfills = process.env.INCLUDE_POLYFILLS;
10-
export default {
11-
input: requirePolyfills ? 'lib/esm-including-polyfills/index.js' : 'lib/esm/index.js',
12-
output: {
13-
file: requirePolyfills
14-
? 'dist/stringToReactComponent.including-polyfills.umd.min.js'
15-
: 'dist/stringToReactComponent.umd.min.js',
16-
format: 'umd',
17-
name,
18-
globals: {
19-
'react-dom': 'ReactDOM',
20-
react: 'React',
21-
'@babel/standalone': 'Babel',
22-
},
23-
sourcemap: true,
9+
const Config = ({en, inputPath = '', outputFile = 'stringToReactComponent', pf = false}) => {
10+
var pfName = pf ? '.including-polyfills' : '';
11+
return {
12+
input: `lib/${pf ? 'esm-including-polyfills' : 'esm'}/${inputPath}index.js`,
13+
output: {
14+
file: `dist/${outputFile}${pfName}.umd${en === 'dev' ? '' : '.min'}.js`,
15+
format: 'umd',
16+
name,
17+
globals: {
18+
'react-dom': 'ReactDOM',
19+
react: 'React',
20+
'@babel/standalone': 'Babel',
21+
},
22+
sourcemap: true,
23+
},
24+
plugins: (function () {
25+
const _plugins = [nodeResolve({preferBuiltins: false}), commonjs()];
26+
if (en === 'prod') {
27+
_plugins.push(terser());
28+
}
29+
return _plugins;
30+
})(),
31+
external: function (id) {
32+
return /prop-types$|react$|\@babel\/standalone$|react-dom$|.test.js$|.js.snap$|.css$/g.test(id);
33+
},
34+
};
2435
},
25-
plugins: [terser(), commonjs(), nodeResolve({preferBuiltins: false})],
26-
external: function (id) {
27-
return /prop-types$|react$|\@babel\/standalone$|react-dom$|.test.js$|.js.snap$|.css$/g.test(id);
28-
},
29-
};
36+
ConfigFactory = (op) => [
37+
Config({en: 'dev', ...op}),
38+
Config({en: 'prod', ...op}),
39+
Config({en: 'dev', pf: true, ...op}),
40+
Config({en: 'prod', pf: true, ...op}),
41+
];
42+
export default ConfigFactory();

webpack.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ module.exports = (env) => {
1010
entry: './src/index.js',
1111
output: {
1212
filename: isProduction ? 'stringToReactComponent.umd.min.js' : 'stringToReactComponent.umd.js',
13-
path: path.resolve(__dirname, 'dist'),
13+
path: path.resolve(__dirname, 'build'),
1414
library,
1515
libraryTarget: 'umd',
16-
publicPath: '/dist/',
16+
publicPath: '/build/',
1717
umdNamedDefine: true,
1818
},
1919
devtool: isProduction ? 'source-map' : 'inline-source-map',
@@ -27,6 +27,10 @@ module.exports = (env) => {
2727
loader: 'babel-loader',
2828
},
2929
},
30+
{
31+
test: /\.css$/i,
32+
use: ['style-loader', 'css-loader'],
33+
},
3034
],
3135
},
3236
resolve: {

0 commit comments

Comments
 (0)