Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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.

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

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

const { createConfig, defineConstants, env, entryPoint, setOutput, sourceMaps, addPlugins } = require('@webpack-blocks/webpack2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Destructuring assignments are not fully supported in node4. I guess we want to keep support to both 4 and 6 for the moment?

const babel = require('@webpack-blocks/babel6');
const devServer = require('@webpack-blocks/dev-server2');
const postcss = require('@webpack-blocks/postcss');
const sass = require('@webpack-blocks/sass');
const typescript = require('@webpack-blocks/typescript');
const tslint = require('@webpack-blocks/tslint');
const extractText = require('@webpack-blocks/extract-text2');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do we need the progress bar for?

const CopyWebpackPlugin = require('copy-webpack-plugin');
const BabiliPlugin = require('babili-webpack-plugin');
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we use uglify, do we need babili?

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(),
sass(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we leave css related configs to a later PR where we just deal with that ? (saas, autoprefixer,..)

extractText('[name].[contenthash].css', 'text/x-sass'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extract the css out of the webpack bundle

postcss([
autoprefixer({ browsers: ['last 2 versions'] })
]),
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()
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the sourceMaps default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cheap-module-source-map
never had issues with them

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, yes that's the one I also use them, just wanted to learn about its preset. We should comment those things above them, I think will be super valuable for people that don't know blocks

]),
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