Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(package): update karma and webpack #3383

Merged
merged 4 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babel-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = () => ({
[
'@babel/env',
{
modules: isESBuild ? false : 'commonjs',
modules: isESBuild || isUMDBuild ? false : 'commonjs',
targets: { browsers },
},
],
Expand Down
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const config = {
// ----------------------------------
// Compiler Configuration
// ----------------------------------
compiler_devtool: (__DEV__ || __TEST__) && 'cheap-source-map',
compiler_devtool: (__DEV__ || __TEST__) && 'cheap-eval-source-map',
compiler_globals: {
'process.env': {
NODE_ENV: JSON.stringify(env),
Expand Down
6 changes: 1 addition & 5 deletions karma.conf.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ export default (karmaConfig) => {
'test/tests.bundle.js': ['webpack'],
},
webpack: {
...webpackConfig,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now spreading keys that aren't applicable to karma's webpack config (name, mode, target, output, etc). I think we should stick with explicitly passing only the keys we want as it was before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we have only webpack.config.karma.js, so I cleaned up it more and removed name, output, target from there.

mode is required setting for Webpack 4, otherwise it will run in production mode.

entry: './test/tests.bundle.js',
externals: webpackConfig.externals,
devtool: config.compiler_devtool,
module: webpackConfig.module,
plugins: webpackConfig.plugins,
resolve: webpackConfig.resolve,
},
webpackServer: {
progress: false,
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@
"gulp-load-plugins": "^1.5.0",
"gulp-util": "^3.0.8",
"husky": "^0.14.3",
"imports-loader": "^0.7.1",
"karma": "^3.0.0",
"imports-loader": "^0.8.0",
"karma": "^3.1.4",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^1.0.1",
"karma-cli": "^2.0.0",
"karma-coverage": "^1.1.2",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-webpack-with-fast-source-maps": "^1.10.2",
"karma-webpack": "^4.0.0-rc.5",
"leven": "^2.1.0",
"lint-staged": "^7.2.2",
"mocha": "^5.2.0",
"prettier": "^1.15.3",
"puppeteer": "^1.7.0",
"raw-loader": "^0.5.1",
"raw-loader": "^1.0.0",
"react": "^16.6.0",
"react-ace": "^6.2.0",
"react-docgen": "^3.0.0-rc.1",
Expand All @@ -164,8 +164,9 @@
"tslint-config-airbnb": "^5.11.0",
"typescript": "^2.9.2",
"vinyl": "^2.2.0",
"webpack": "^3.6.0",
"webpack-dev-middleware": "^1.12.0"
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1",
"webpack-dev-middleware": "^3.5.0"
},
"peerDependencies": {
"react": "^16.3.0",
Expand Down
2 changes: 1 addition & 1 deletion static.webpack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import webpack from 'webpack'
import webpack from 'react-static/node_modules/webpack'

import config from './config'

Expand Down
21 changes: 14 additions & 7 deletions test/specs/addons/Responsive/Responsive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,36 @@ describe('Responsive', () => {

describe('render', () => {
it('does not re render if fit does not change', () => {
sandbox.stub(window, 'innerWidth').value(Responsive.onlyTablet.minWidth + 1)

const wrapper = mount(<Responsive {...Responsive.onlyTablet} />)
const instance = wrapper.instance()
const spy = sandbox.spy(instance, 'render')
sandbox.stub(window, 'innerWidth').value(Responsive.onlyTablet.minWidth + 1)
const render = sandbox.spy(instance, 'render')

domEvent.fire(window, 'resize')
spy.should.not.have.been.called()
render.should.not.have.been.called()
})

it('re renders if fit changes', () => {
sandbox.stub(window, 'innerWidth').value(Responsive.onlyTablet.minWidth)

const wrapper = mount(<Responsive {...Responsive.onlyTablet} />)
const instance = wrapper.instance()
const spy = sandbox.spy(instance, 'render')
const render = sandbox.spy(instance, 'render')

sandbox.stub(window, 'innerWidth').value(Responsive.onlyTablet.minWidth - 1)
domEvent.fire(window, 'resize')
spy.should.have.been.calledOnce()

render.should.have.been.calledOnce()
})

it('re renders when props change', () => {
const wrapper = mount(<Responsive {...Responsive.onlyMobile} />)
const instance = wrapper.instance()
const spy = sandbox.spy(instance, 'render')
const render = sandbox.spy(instance, 'render')

wrapper.setProps({ as: 'h1' })
spy.should.have.been.called()
render.should.have.been.called()
})
})
})
82 changes: 22 additions & 60 deletions webpack.karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,31 @@ const config = require('./config')
const { paths } = config

const webpackConfig = {
name: 'client',
target: 'web',
mode: 'development',
externals: {
'@babel/standalone': 'Babel',
lodash: '_',
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/server': 'ReactDOMServer',
},
devtool: config.compiler_devtool,
module: {
noParse: [],
rules: [],
noParse: [/typescript\/lib/],
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
},
],
},
plugins: [],
plugins: [new webpack.DefinePlugin(config.compiler_globals)],
resolve: {
modules: [paths.base(), 'node_modules'],
alias: {
Expand All @@ -20,59 +37,4 @@ const webpackConfig = {
},
}

// ------------------------------------
// Bundle Output
// ------------------------------------
webpackConfig.output = {
...webpackConfig.output,
filename: `[name].[${config.compiler_hash_type}].js`,
path: config.compiler_output_path,
pathinfo: true,
publicPath: config.compiler_public_path,
}

// ------------------------------------
// Plugins
// ------------------------------------
webpackConfig.plugins = [
...webpackConfig.plugins,
new webpack.DefinePlugin(config.compiler_globals),
]

// ------------------------------------
// Externals
// ------------------------------------
webpackConfig.externals = {
'@babel/standalone': 'Babel',
lodash: '_',
react: 'React',
'react-dom': 'ReactDOM',
'react-dom/server': 'ReactDOMServer',
}

// ------------------------------------
// No Parse
// ------------------------------------
webpackConfig.module.noParse = [...webpackConfig.module.noParse, /\.json$/, /typescript\/lib/]

// ------------------------------------
// Rules
// ------------------------------------
webpackConfig.module.rules = [
...webpackConfig.module.rules,
{
//
// Babel
//
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
},
]

module.exports = webpackConfig
28 changes: 17 additions & 11 deletions webpack.umd.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const webpack = require('webpack')

const config = require('./config')
const pkg = require('./package.json')
const webpackConfig = require('./webpack.karma.config')

const { paths } = config

Expand All @@ -16,6 +15,7 @@ const webpackUMDConfig = {
react: 'React',
'react-dom': 'ReactDOM',
},
mode: 'production',
output: {
filename: '[name].min.js',
libraryTarget: 'umd',
Expand All @@ -28,18 +28,24 @@ const webpackUMDConfig = {
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false,
},
output: { comments: false },
}),
],
module: {
noParse: webpackConfig.module.noParse,
rules: webpackConfig.module.rules,
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
},
],
},
performance: {
maxEntrypointSize: 750000,
maxAssetSize: 750000,
},
}

Expand Down
Loading