-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
93be209
6b18b84
adeb930
9a20d66
70d5e11
714d9dc
b2b9e2f
d2b26f0
b7ed2fd
39296f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
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 = { | ||
// 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)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
new CopyWebpackPlugin([{ from: 'public', to: '' }]) | ||
]) | ||
]) | ||
] | ||
|
||
const config = language === 'javascript' ? baseConfig : baseConfig | ||
.concat([ | ||
typescript(), | ||
tslint() | ||
]) | ||
|
||
return createConfig(config) | ||
} |
This file was deleted.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 thatThere was a problem hiding this comment.
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