Created
December 2, 2016 13:30
-
-
Save awv-inf/257464c57fd19b656858c6ffd5a87c91 to your computer and use it in GitHub Desktop.
redux example config
This file contains 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
import path from "path"; | |
import webpack from "webpack"; | |
module.exports = env => { | |
const devBabelPresets = env.dev ? [ | |
["env", { modules: false, loose: true, "targets": { "chrome": 55 } }] | |
] : []; | |
const prodBabelPresets = env.prod ? [ | |
["es2015", { modules: false, loose: true }], | |
"stage-0" | |
] : []; | |
const devBabelPlugins = env.dev ? [ | |
"react-hot-loader/babel" | |
] : []; | |
const prodBabelPlugins = env.prod ? [ | |
"transform-runtime" | |
] : []; | |
const babelConfig = { | |
babelrc: false, | |
cacheDirectory: true, | |
presets: [ | |
...devBabelPresets, | |
...prodBabelPresets, | |
"react" | |
], | |
plugins: [ | |
...devBabelPlugins, | |
...prodBabelPlugins, | |
"transform-export-extensions", | |
"transform-object-rest-spread", | |
"transform-decorators-legacy", | |
"transform-class-properties", | |
["csjs-postcss", { "plugins": ["postcss-cssnext", "csswring"] }], | |
["import", { libraryName: "antd", style: "css" }] | |
] | |
}; | |
const devPlugins = env.dev ? [ | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.NamedModulesPlugin() | |
] : []; | |
const prodPlugins = env.prod ? [ | |
new webpack.DefinePlugin({ "process.env": { "NODE_ENV": JSON.stringify("production") } }), | |
new webpack.LoaderOptionsPlugin({ minimize: true, debug: false }), | |
new webpack.optimize.UglifyJsPlugin({ compress: { | |
warnings: false, | |
screw_ie8: true, | |
drop_console: true, | |
drop_debugger: true, | |
dead_code: true, | |
global_defs: { __REACT_HOT_LOADER__: undefined } | |
}, mangle: true }) | |
] : []; | |
const prodAliases = env.prod ? { | |
"react": "react-lite", | |
"react-dom": "react-lite" | |
} : {}; | |
const devEntries = env.dev ? [ | |
"webpack-dev-server/client?http://localhost:8080", | |
"webpack/hot/only-dev-server", | |
"react-hot-loader/patch", | |
] : []; | |
return { | |
entry: [ | |
...devEntries, | |
__dirname + "/index.js" | |
], | |
output: { | |
filename: "build/bundle.js", | |
path: __dirname, | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.js$/, loader: "babel-loader", query: babelConfig, exclude: /(node_modules)/ }, | |
{ test: /\.css$/, loader: "style-loader!css-loader" }, | |
{ test: /\.glsl$/, loader: "webpack-glsl-loader" } | |
] | |
}, | |
resolve: { | |
modules: [path.resolve("./"), "node_modules"], | |
extensions: [".js", ".jsx"], | |
alias: { | |
awv3: "src", | |
three: "three/src/Three.js", | |
...prodAliases | |
} | |
}, | |
plugins: [ | |
new webpack.LoaderOptionsPlugin({ | |
options: { worker: { output: { filename: "build/worker.js" } } } }), | |
...devPlugins, | |
...prodPlugins | |
], | |
devServer: { | |
hot: env.dev, | |
contentBase: __dirname | |
}, | |
devtool: (env.dev ? "source-maps" : undefined) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment