Last active
June 30, 2018 00:38
-
-
Save hectorgool/dfbac96fc56e76563d8fa708958e4915 to your computer and use it in GitHub Desktop.
webpack template production and develop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
module.exports = (env) => { | |
const plugins = [ | |
new ExtractTextPlugin("css/[name].[hash].css") | |
] | |
if (env.NODE_ENV === 'production') { | |
plugins.push( | |
new CleanWebpackPlugin(['dist'], {root: __dirname}) | |
) | |
} | |
return { | |
entry: { | |
"santo": path.resolve(__dirname, 'src/index.js'), | |
}, | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
filename: 'js/[name].[hash].js', | |
publicPath: path.resolve(__dirname, 'dist')+"/", | |
chunkFilename: 'js/[id].[chunkhash].js', | |
}, | |
devServer: { | |
port: 9000, | |
}, | |
module: { | |
rules: [ | |
{ | |
// test: que tipo de archivo quiero reconocer, | |
// use: que loader se va a encargar del archivo | |
test: /\.(js|jsx)$/, | |
exclude: /(node_modules)/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['es2015', 'react', 'stage-2'], | |
} | |
}, | |
}, | |
{ | |
test: /\.css$/, | |
use: ExtractTextPlugin.extract({ | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
minimize: true, | |
} | |
} | |
] | |
}) | |
}, | |
{ | |
test: /\.(jpg|png|gif|svg)$/, | |
use: { | |
loader: 'url-loader', | |
options: { | |
limit: 10000, | |
fallback: 'file-loader', | |
name: 'images/[name].[hash].[ext]', | |
} | |
} | |
}, | |
] | |
}, | |
plugins | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
module.exports = { | |
entry: { | |
"santo": path.resolve(__dirname, 'src/index.js'), | |
}, | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
filename: 'js/[name].js' | |
}, | |
devServer: { | |
port: 9000, | |
}, | |
devtool:'eval-source-map', | |
module: { | |
rules: [ | |
{ | |
// test: que tipo de archivo quiero reconocer, | |
// use: que loader se va a encargar del archivo | |
test: /\.(js|jsx)$/, | |
exclude: /(node_modules)/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
presets: ['es2015', 'react', 'stage-2'], | |
} | |
}, | |
}, | |
{ | |
test: /\.css$/, | |
use: ['style-loader', 'css-loader'] | |
}, | |
{ | |
test: /\.(jpg|png|gif|svg)$/, | |
use: { | |
loader: 'url-loader', | |
options: { | |
limit: 1000000, | |
fallback: 'file-loader', | |
name: 'images/[name].[hash].[ext]', | |
} | |
} | |
}, | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment