-
Notifications
You must be signed in to change notification settings - Fork 21
Add new webpack config #105
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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,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'); | ||
| 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'); | ||
|
Collaborator
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. What do we need the progress bar for? |
||
| const CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
| const BabiliPlugin = require('babili-webpack-plugin'); | ||
|
Collaborator
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. If we use uglify, do we need babili? |
||
| const path = require('path'); | ||
|
|
||
| const babelConfig = { | ||
|
Collaborator
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. with
Collaborator
Author
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. yes, but it will be shared with typescript
Collaborator
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. 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
Collaborator
Author
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. 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)), | ||
|
Collaborator
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
Collaborator
Author
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(), | ||
| sass(), | ||
|
Collaborator
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. 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'), | ||
|
Collaborator
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. What is this for?
Collaborator
Author
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. 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() | ||
|
Collaborator
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. what is the sourceMaps default?
Collaborator
Author
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.
Collaborator
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. 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(), | ||
|
Collaborator
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?
Collaborator
Author
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.
Destructuring assignments are not fully supported in node4. I guess we want to keep support to both 4 and 6 for the moment?