migrate webpack to v2.6.1
This commit is contained in:
@@ -3,11 +3,8 @@ var path = require('path')
|
||||
var webpack = require('webpack')
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||
var deepExtend = require('deep-extend')
|
||||
var autoprefixer = require('autoprefixer')
|
||||
const {gitDescribeSync} = require('git-describe');
|
||||
|
||||
var loadersByExtension = require('./build-tools/loadersByExtension')
|
||||
|
||||
var pkg = require('./package.json')
|
||||
|
||||
let gitInfo
|
||||
@@ -21,7 +18,27 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function(options) {
|
||||
var commonRules = [
|
||||
{ test: /\.(js(x)?)(\?.*)?$/,
|
||||
use: [{
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
retainLines: true
|
||||
}
|
||||
}],
|
||||
include: [ path.join(__dirname, 'src') ]
|
||||
},
|
||||
{ test: /\.(txt|yaml)(\?.*)?$/,
|
||||
loader: 'raw-loader' },
|
||||
{ test: /\.(png|jpg|jpeg|gif|svg)(\?.*)?$/,
|
||||
loader: 'url-loader?limit=10000' },
|
||||
{ test: /\.(woff|woff2)(\?.*)?$/,
|
||||
loader: 'url-loader?limit=100000' },
|
||||
{ test: /\.(ttf|eot)(\?.*)?$/,
|
||||
loader: 'file-loader' }
|
||||
]
|
||||
|
||||
module.exports = function(rules, options) {
|
||||
|
||||
// Special options, that have logic in this file
|
||||
// ...with defaults
|
||||
@@ -33,23 +50,11 @@ module.exports = function(options) {
|
||||
sourcemaps: false,
|
||||
}, options._special)
|
||||
|
||||
var loadersMap = {
|
||||
'js(x)?': {
|
||||
loader: 'babel?retainLines=true',
|
||||
include: [ path.join(__dirname, 'src') ],
|
||||
},
|
||||
'json': 'json-loader',
|
||||
'txt|yaml': 'raw-loader',
|
||||
'png|jpg|jpeg|gif|svg': specialOptions.disableAssets ? 'null-loader' : 'url-loader?limit=10000',
|
||||
'woff|woff2': specialOptions.disableAssets ? 'null-loader' : 'url-loader?limit=100000',
|
||||
'ttf|eot': specialOptions.disableAssets ? 'null-loader' : 'file-loader',
|
||||
"worker.js": ["worker-loader?inline=true", "babel"]
|
||||
}
|
||||
|
||||
var plugins = []
|
||||
|
||||
if( specialOptions.separateStylesheets ) {
|
||||
plugins.push(new ExtractTextPlugin('[name].css' + (specialOptions.longTermCaching ? '?[contenthash]' : ''), {
|
||||
plugins.push(new ExtractTextPlugin({
|
||||
filename: '[name].css' + (specialOptions.longTermCaching ? '?[contenthash]' : ''),
|
||||
allChunks: true
|
||||
}))
|
||||
}
|
||||
@@ -58,11 +63,13 @@ module.exports = function(options) {
|
||||
|
||||
plugins.push(
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compressor: {
|
||||
warnings: false
|
||||
}
|
||||
sourceMap: true,
|
||||
}),
|
||||
new webpack.optimize.DedupePlugin()
|
||||
new webpack.LoaderOptionsPlugin({
|
||||
options: {
|
||||
context: __dirname
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
plugins.push( new webpack.NoErrorsPlugin())
|
||||
@@ -83,34 +90,7 @@ module.exports = function(options) {
|
||||
})
|
||||
}))
|
||||
|
||||
var cssLoader = 'css-loader!postcss-loader'
|
||||
|
||||
var completeStylesheetLoaders = deepExtend({
|
||||
'css': cssLoader,
|
||||
'scss': cssLoader + '!' + 'sass-loader?outputStyle=expanded&sourceMap=true&sourceMapContents=true',
|
||||
'less': cssLoader + '!' + 'less-loader',
|
||||
}, specialOptions.stylesheetLoaders)
|
||||
|
||||
if(specialOptions.cssModules) {
|
||||
cssLoader = cssLoader + '?module' + (specialOptions.minimize ? '' : '&localIdentName=[path][name]---[local]---[hash:base64:5]')
|
||||
}
|
||||
|
||||
Object.keys(completeStylesheetLoaders).forEach(function(ext) {
|
||||
var ori = completeStylesheetLoaders[ext]
|
||||
if(specialOptions.separateStylesheets) {
|
||||
completeStylesheetLoaders[ext] = ExtractTextPlugin.extract('style-loader', ori)
|
||||
} else {
|
||||
completeStylesheetLoaders[ext] = 'style-loader!' + ori
|
||||
}
|
||||
})
|
||||
|
||||
var loaders = loadersByExtension(deepExtend({}, loadersMap, specialOptions.loaders, completeStylesheetLoaders))
|
||||
var extraLoaders = (options.module || {} ).loaders
|
||||
|
||||
if(Array.isArray(extraLoaders)) {
|
||||
loaders = loaders.concat(extraLoaders)
|
||||
delete options.module.loaders
|
||||
}
|
||||
delete options._special
|
||||
|
||||
var completeConfig = deepExtend({
|
||||
entry: {},
|
||||
@@ -130,11 +110,11 @@ module.exports = function(options) {
|
||||
},
|
||||
|
||||
module: {
|
||||
loaders: loaders,
|
||||
rules: commonRules.concat(rules),
|
||||
},
|
||||
|
||||
resolveLoader: {
|
||||
root: path.join(__dirname, 'node_modules'),
|
||||
modules: [path.join(__dirname, 'node_modules')],
|
||||
},
|
||||
|
||||
externals: {
|
||||
@@ -142,19 +122,16 @@ module.exports = function(options) {
|
||||
},
|
||||
|
||||
resolve: {
|
||||
root: path.join(__dirname, './src'),
|
||||
modulesDirectories: ['node_modules'],
|
||||
extensions: ["", ".web.js", ".js", ".jsx", ".json", ".less"],
|
||||
packageAlias: 'browser',
|
||||
modules: [
|
||||
path.join(__dirname, './src'),
|
||||
'node_modules'
|
||||
],
|
||||
extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
|
||||
alias: {
|
||||
base: "getbase/src/less/base"
|
||||
}
|
||||
},
|
||||
|
||||
postcss: function() {
|
||||
return [autoprefixer]
|
||||
},
|
||||
|
||||
devtool: specialOptions.sourcemaps ? 'cheap-module-source-map' : null,
|
||||
|
||||
plugins,
|
||||
|
||||
Reference in New Issue
Block a user