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

Add new webpack config #105

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
103 changes: 0 additions & 103 deletions packages/cycle-scripts/configs/javascript/webpack.config.dev.js

This file was deleted.

92 changes: 0 additions & 92 deletions packages/cycle-scripts/configs/javascript/webpack.config.prod.js

This file was deleted.

92 changes: 92 additions & 0 deletions packages/cycle-scripts/configs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict'

// Silence webpack2 deprecation warnings
// https://github.com/vuejs/vue-loader/issues/666
process.noDeprecation = true

const webpack2Block = require('@webpack-blocks/webpack2');
const createConfig = webpack2Block.createConfig
const defineConstants = webpack2Block.defineConstant
const env = webpack2Block.env
const entryPoint = webpack2Block.entryPoint
const setOutput = webpack2Block.setOutput
const sourceMaps = webpack2Block.sourceMaps
const addPlugins = webpack2Block.addPlugins

const babel = require('@webpack-blocks/babel6');
const devServer = require('@webpack-blocks/dev-server2');
const typescript = require('@webpack-blocks/typescript');
const tslint = require('@webpack-blocks/tslint');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const path = require('path');

const babelConfig = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

with babelConfig you mean babel-loader config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, but it will be shared with typescript

Copy link
Collaborator

Choose a reason for hiding this comment

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

what will be shared the babel config or the babel-loader config? as in there there are things that are pure babel-loader for webpack related as cacheDirectory: true. Perhpash we can make this more evident and with better naming of what get shared and what not? Otherwise I think we'll be sharing with ts stuff that he doesn't need/support and I'll rather avoid that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Have removed the loader specific bit, as babel would complain

// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/babel-loader/
// directory for faster rebuilds.
cacheDirectory: true,
// Instead of relying on a babelrc file to configure babel (or in package.json configs)
// We speficy here which presets to use. In the future this could be moved to it's own
// package as create-react-app does with their 'babel-preset-react-app module.
// As uglify doesn't support es6 code yet, the uglify param will tell babel plugin to transpile to es5
// in order for the output to be uglified.
presets: [
[ 'env', {
'targets': {
'browsers': ['last 2 versions'],
uglify: true
}
}]
],
plugins: [
// https://cycle.js.org/getting-started.html#getting-started-coding-consider-jsx
// This allow us to use JSX to create virtual dom elements instead of Snabbdom helpers like div(), input(), ..
['transform-react-jsx', { pragma: 'Snabbdom.createElement' }],
// Allow Babel to transform rest properties for object destructuring assignment and spread properties for object literals.
['transform-object-rest-spread']
]
}

module.exports = function(language) {
const ending = language === 'javascript' ? 'js' : 'ts'
const baseConfig = [
entryPoint(path.join(process.cwd(), 'src', 'index' + ending)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we really need blocks for those? Not sure I see the whole benefits for entryPoint and setOutput

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for consitency, I would say yes

setOutput(path.join(process.cwd(), 'build', 'bundle.[hash].js')),
babel(),
defineConstants({
'process.env.NODE_ENV': process.env.NODE_ENV
}),
addPlugins([
new HtmlWebpackPlugin({
template: 'public/index.html',
inject: true,
favicon: 'public/favicon.png',
hash: true
}),
new webpack.ProvidePlugin({
Snabbdom: 'snabbdom-pragma'
})
]),
env('development', [
devServer({}, require.resolve('react-dev-utils/webpackHotDevClient')),
sourceMaps() //The default is cheap-module-source-map
]),
env('production', [
addPlugins([
new webpack.optimize.UglifyJsPlugin(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we want Uglify to also work with maps as per our sourcemaps settings perhaps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are source maps needed in production? Currently I only added them in the dev environment

new CopyWebpackPlugin([{ from: 'public', to: '' }])
])
])
]

const config = language === 'javascript' ? baseConfig : baseConfig
.concat([
typescript(),
tslint()
])

return createConfig(config)
}
91 changes: 0 additions & 91 deletions packages/cycle-scripts/configs/webpackDevServer.config.js

This file was deleted.

Loading