Skip to content

Commit

Permalink
fix(build): properly include build/ in published package
Browse files Browse the repository at this point in the history
refactor webpack, babel & karma config

Fixes #425, #426
  • Loading branch information
STRML committed Sep 9, 2019
1 parent a214ac6 commit ad8b499
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
10 changes: 8 additions & 2 deletions .babelrc → .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
'use strict';

const targets = process.env.IS_WEBPACK === "1" ?
"> 0.25%, not dead" :
"maintained node versions"

module.exports = {
"presets": [
[
"@babel/preset-env",
{
"modules": false
targets
}
],
"@babel/react",
Expand Down
File renamed without changes.
44 changes: 19 additions & 25 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var webpack = require('webpack');
'use strict';

const webpack = require('webpack');
const _ = require('lodash');
process.env.NODE_ENV = 'test';
process.env.CHROME_BIN = require('puppeteer').executablePath();

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

webpack: {
mode: 'production',
module: {
// Suppress power-assert warning
exprContextCritical: false,
rules: [
{
test: /\.(?:js|es).?$/,
loader: 'babel-loader?cacheDirectory',
exclude: /(node_modules)/
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"test"'
}
})
],
performance: {
hints: false
}
},
webpack: _.merge(
require('./webpack.config.js')({}, {}),
{
mode: 'production',
module: {
// Suppress power-assert warning
exprContextCritical: false,
},
performance: {
hints: false,
},
// zero out externals; we want to bundle React
externals: '',
}
),

webpackServer: {
stats: {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "4.0.1",
"description": "React draggable component",
"main": "index.js",
"browser": "web/react-draggable.js",
"browser": "web/react-draggable.min.js",
"scripts": {
"test": "make test",
"test-debug": "karma start --browsers=Chrome",
Expand All @@ -14,7 +14,8 @@
"flow": "flow"
},
"files": [
"/lib"
"/build",
"/web/react-draggable.min.js"
],
"typings": "./typings/index.d.ts",
"types": "./typings/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion specs/draggable.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';
import ShallowRenderer from 'react-test-renderer/shallow';
import Draggable, {DraggableCore} from '../index-babel';
import Draggable, {DraggableCore} from '../index-src';
import FrameComponent from 'react-frame-component';
import assert from 'power-assert';
import _ from 'lodash';
Expand Down
26 changes: 17 additions & 9 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
// Grabbed in .babelrc.js to switch on preset-env target.
// If we're in webpack, we compile for browsers, otherwise we compile for modern Node.
process.env.IS_WEBPACK = "1";

module.exports = (env, argv) => ({
entry: {
"react-draggable": "./index.js",
"react-draggable.min": "./index.js",
"react-draggable": "./index-src.js",
"react-draggable.min": "./index-src.js",
},
output: {
filename: '[name].js',
Expand Down Expand Up @@ -42,16 +46,21 @@ module.exports = {
rules: [
{
test: /\.(?:js|es).?$/,
loader: 'babel-loader?cacheDirectory',
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
exclude: /(node_modules)/
}
]
},
plugins: [
new webpack.EnvironmentPlugin({
// Default values
DRAGGABLE_DEBUG: false,
NODE_ENV: 'production'
DRAGGABLE_DEBUG: argv.mode === 'development',
NODE_ENV: ['development', 'production'].includes(argv.mode) ?
argv.mode :
(process.env.NODE_ENV || 'production'),
}),
// Scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
Expand All @@ -60,8 +69,7 @@ module.exports = {
minimizer: [new TerserPlugin({
include: /\.min\.js$/,
sourceMap: true,
terserOptions: {
}
terserOptions: {}
})],
}
};
});

0 comments on commit ad8b499

Please sign in to comment.