Skip to content

Commit

Permalink
Merge pull request #37 from doxiaodong/develop
Browse files Browse the repository at this point in the history
develop -> master
  • Loading branch information
doxiaodong authored Feb 17, 2017
2 parents 9db3630 + f0d88c4 commit ddd443e
Show file tree
Hide file tree
Showing 20 changed files with 305 additions and 217 deletions.
116 changes: 75 additions & 41 deletions config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ console.log(chalk.green('is aot?'), AOT ? chalk.green('true') : chalk.red('false
/**
* Webpack configuration
*
* See: http://webpack.github.io/docs/configuration.html#cli
* See: https://webpack.js.org/configuration/
*/
module.exports = function(option) {
const isProd = option.env === 'production'
Expand All @@ -34,13 +34,13 @@ module.exports = function(option) {
/**
* Options affecting the resolving of modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve
* See: https://webpack.js.org/configuration/resolve/#resolve
*/
resolve: {
/**
* An array of extensions that should be used to resolve modules.
*
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions
* See: https://webpack.js.org/configuration/resolve/#resolve-extensions
*/
extensions: ['.ts', '.js'],

Expand All @@ -54,13 +54,19 @@ module.exports = function(option) {
/**
* Options affecting the normal modules.
*
* See: http://webpack.github.io/docs/configuration.html#module
* See: https://webpack.js.org/configuration/module/
*/
module: {
rules: [{
test: /\.ts$/,
use: [
'@angularclass/hmr-loader?pretty=' + !isProd + '&prod=' + isProd,
{
loader: '@angularclass/hmr-loader',
options: {
pretty: !isProd,
prod: isProd
}
},
{
loader: 'ng-router-loader',
options: {
Expand All @@ -69,16 +75,24 @@ module.exports = function(option) {
aot: AOT
}
},
'ts-loader?{configFileName: "tsconfig' + (AOT ? '.aot' : '') + '.json"}',
{
loader: 'ts-loader',
options: {
configFileName: 'tsconfig' + (AOT ? '.aot' : '') + '.json'
}
},
'angular2-template-loader'
],
exclude: [/\.(spec|e2e)\.ts$/]
},
{
test: /\.svg$/,
use: 'svg-sprite-loader?' + JSON.stringify({
name: '[name]-[hash]'
})
use: {
loader: 'svg-sprite-loader',
options: {
name: '[name]-[hash]'
}
}
},
/**
* Json loader support for *.json files.
Expand All @@ -92,9 +106,17 @@ module.exports = function(option) {
},
{
test: /(global|\.min)\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader?minimize!postcss-loader'
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true
}
},
'postcss-loader'
]
})
},
/**
Expand All @@ -113,21 +135,31 @@ module.exports = function(option) {
},
{
test: /global\.less$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
'css-loader?minimize',
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true
}
},
'postcss-loader',
'less-loader'
]
})
},
{
test: /global\.scss$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
'css-loader?minimize',
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
minimize: true
}
},
'postcss-loader',
'sass-loader'
]
Expand Down Expand Up @@ -169,8 +201,25 @@ module.exports = function(option) {
{
test: /\.(jpe?g|png|gif)$/i,
use: [
`file-loader?hash=sha512&digest=hex&name=${helpers.static}[name]-[hash]`,
'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
{
loader: 'file-loader',
options: {
hash: 'sha512',
digest: 'hex',
name: helpers.static + '[name]-[hash]'
}
},
{
loader: 'image-webpack-loader',
options: {
gifsicle: {
interlaced: false
},
optipng: {
optimizationLevel: 7
}
}
}
]
}]

Expand All @@ -179,7 +228,7 @@ module.exports = function(option) {
/**
* Add additional plugins to the compiler.
*
* See: http://webpack.github.io/docs/configuration.html#plugins
* See: https://webpack.js.org/configuration/plugins/
*/
plugins: [
new HtmlElementsPlugin({
Expand All @@ -203,28 +252,13 @@ module.exports = function(option) {
* Description: Shares common code between the pages.
* It identifies common modules and put them into a commons chunk.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
* See: https://webpack.js.org/plugins/commons-chunk-plugin/
* See: https://github.com/webpack/docs/wiki/optimization#multi-page-app
*/
new webpack.optimize.CommonsChunkPlugin({
name: ['lib']
}),

// new webpack.optimize.CommonsChunkPlugin({
// name: 'lib',
// chunks: ['lib']
// }),

// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor',
// chunks: ['main'],
// minChunks: module => /node_modules\//.test(module.resource)
// }),

// new webpack.optimize.CommonsChunkPlugin({
// name: ['lib', 'vendor'].reverse()
// }),

/**
* Plugin: CopyWebpackPlugin
* Description: Copy files and directories in webpack.
Expand Down Expand Up @@ -267,7 +301,7 @@ module.exports = function(option) {
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src') // location of oyour src
helpers.root('./src') // location of your src
),

new ngcWebpack.NgcWebpackPlugin({
Expand All @@ -281,7 +315,7 @@ module.exports = function(option) {
* Include polyfills or mocks for various node stuff
* Description: Node configuration
*
* See: https://webpack.github.io/docs/configuration.html#node
* See: https://webpack.js.org/configuration/node/
*/
node: {
global: true,
Expand Down
26 changes: 13 additions & 13 deletions config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
/**
* Options affecting the output of the compilation.
*
* See: http://webpack.github.io/docs/configuration.html#output
* See: https://webpack.js.org/configuration/output/
*/
output: {

/**
* The output directory as absolute path (required).
*
* See: http://webpack.github.io/docs/configuration.html#output-path
* See: https://webpack.js.org/configuration/output/#output-path
*/
path: helpers.root('dist'),

Expand All @@ -61,42 +61,42 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
* Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here!
*
* See: http://webpack.github.io/docs/configuration.html#output-filename
* See: https://webpack.js.org/configuration/output/#output-filename
*/
filename: '[name].bundle.js',

/**
* The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
* See: https://webpack.js.org/configuration/output/#output-sourcemapfilename
*/
sourceMapFilename: '[name].map',

/**
* The filename of non-entry chunks as relative path
* inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
* See: https://webpack.js.org/configuration/output/#output-chunkfilename
*/
chunkFilename: '[id].chunk.js'

},

plugins: [
/**
* Plugin LoaderOptionsPlugin (experimental)
*
* See: https://webpack.js.org/plugins/loader-options-plugin/
*/
new webpack.LoaderOptionsPlugin({
debug: true,
options: {
postcss: [
autoprefixer({
browsers: ['last 1 version', '> 10%']
})
],
/**
* Switch loaders to debug mode.
*
* See: http://webpack.github.io/docs/configuration.html#debug
*/
debug: true,
tslint: {
emitErrors: false,
failOnHint: false,
Expand All @@ -112,7 +112,7 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
*
* Environment helpers
*
* See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
* See: https://webpack.js.org/plugins/define-plugin/
* NOTE: when adding more properties make sure you include them in custom-typings.d.ts
*/
new DefinePlugin({
Expand All @@ -132,7 +132,7 @@ module.exports = webpackMerge(commonConfig({ env: ENV }), {
* The server emits information about the compilation state to the client,
* which reacts to those events.
*
* See: https://webpack.github.io/docs/webpack-dev-server.html
* See: https://webpack.js.org/configuration/dev-server/
*/
devServer: {
port: METADATA.port,
Expand Down
Loading

0 comments on commit ddd443e

Please sign in to comment.