Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit ad8b499

Browse files
committed
fix(build): properly include build/ in published package
refactor webpack, babel & karma config Fixes react-grid-layout#425, react-grid-layout#426
1 parent a214ac6 commit ad8b499

6 files changed

Lines changed: 48 additions & 39 deletions

File tree

.babelrc renamed to .babelrc.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
{
1+
'use strict';
2+
3+
const targets = process.env.IS_WEBPACK === "1" ?
4+
"> 0.25%, not dead" :
5+
"maintained node versions"
6+
7+
module.exports = {
28
"presets": [
39
[
410
"@babel/preset-env",
511
{
6-
"modules": false
12+
targets
713
}
814
],
915
"@babel/react",
File renamed without changes.

karma.conf.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
var webpack = require('webpack');
1+
'use strict';
2+
3+
const webpack = require('webpack');
4+
const _ = require('lodash');
25
process.env.NODE_ENV = 'test';
36
process.env.CHROME_BIN = require('puppeteer').executablePath();
47

@@ -20,30 +23,21 @@ module.exports = function(config) {
2023
'specs/main.js': ['webpack']
2124
},
2225

23-
webpack: {
24-
mode: 'production',
25-
module: {
26-
// Suppress power-assert warning
27-
exprContextCritical: false,
28-
rules: [
29-
{
30-
test: /\.(?:js|es).?$/,
31-
loader: 'babel-loader?cacheDirectory',
32-
exclude: /(node_modules)/
33-
}
34-
]
35-
},
36-
plugins: [
37-
new webpack.DefinePlugin({
38-
'process.env': {
39-
NODE_ENV: '"test"'
40-
}
41-
})
42-
],
43-
performance: {
44-
hints: false
45-
}
46-
},
26+
webpack: _.merge(
27+
require('./webpack.config.js')({}, {}),
28+
{
29+
mode: 'production',
30+
module: {
31+
// Suppress power-assert warning
32+
exprContextCritical: false,
33+
},
34+
performance: {
35+
hints: false,
36+
},
37+
// zero out externals; we want to bundle React
38+
externals: '',
39+
}
40+
),
4741

4842
webpackServer: {
4943
stats: {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "4.0.1",
44
"description": "React draggable component",
55
"main": "index.js",
6-
"browser": "web/react-draggable.js",
6+
"browser": "web/react-draggable.min.js",
77
"scripts": {
88
"test": "make test",
99
"test-debug": "karma start --browsers=Chrome",
@@ -14,7 +14,8 @@
1414
"flow": "flow"
1515
},
1616
"files": [
17-
"/lib"
17+
"/build",
18+
"/web/react-draggable.min.js"
1819
],
1920
"typings": "./typings/index.d.ts",
2021
"types": "./typings/index.d.ts",

specs/draggable.spec.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import ReactDOM from 'react-dom';
44
import TestUtils from 'react-dom/test-utils';
55
import ShallowRenderer from 'react-test-renderer/shallow';
6-
import Draggable, {DraggableCore} from '../index-babel';
6+
import Draggable, {DraggableCore} from '../index-src';
77
import FrameComponent from 'react-frame-component';
88
import assert from 'power-assert';
99
import _ from 'lodash';

webpack.config.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ const path = require('path');
22
const webpack = require('webpack');
33
const TerserPlugin = require('terser-webpack-plugin');
44

5-
module.exports = {
5+
// Grabbed in .babelrc.js to switch on preset-env target.
6+
// If we're in webpack, we compile for browsers, otherwise we compile for modern Node.
7+
process.env.IS_WEBPACK = "1";
8+
9+
module.exports = (env, argv) => ({
610
entry: {
7-
"react-draggable": "./index.js",
8-
"react-draggable.min": "./index.js",
11+
"react-draggable": "./index-src.js",
12+
"react-draggable.min": "./index-src.js",
913
},
1014
output: {
1115
filename: '[name].js',
@@ -42,16 +46,21 @@ module.exports = {
4246
rules: [
4347
{
4448
test: /\.(?:js|es).?$/,
45-
loader: 'babel-loader?cacheDirectory',
49+
loader: 'babel-loader',
50+
options: {
51+
cacheDirectory: true,
52+
},
4653
exclude: /(node_modules)/
4754
}
4855
]
4956
},
5057
plugins: [
5158
new webpack.EnvironmentPlugin({
5259
// Default values
53-
DRAGGABLE_DEBUG: false,
54-
NODE_ENV: 'production'
60+
DRAGGABLE_DEBUG: argv.mode === 'development',
61+
NODE_ENV: ['development', 'production'].includes(argv.mode) ?
62+
argv.mode :
63+
(process.env.NODE_ENV || 'production'),
5564
}),
5665
// Scope hoisting
5766
new webpack.optimize.ModuleConcatenationPlugin(),
@@ -60,8 +69,7 @@ module.exports = {
6069
minimizer: [new TerserPlugin({
6170
include: /\.min\.js$/,
6271
sourceMap: true,
63-
terserOptions: {
64-
}
72+
terserOptions: {}
6573
})],
6674
}
67-
};
75+
});

0 commit comments

Comments
 (0)