-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
require libs for production bundle #292
Comments
You can it i. e.
{
resolve: {
extensions: gulp.env.production ? ["", ".production.js", ".js"] : ["", ".js"]
}
} require("libpath/lib");
{
plugins: [
new webpack.DefinePlugin({
PRODUCTION: JSON.stringify(!!gulp.env.production)
})
]
} if(PRODUCTION)
require("libpath/lib.production.js");
else
require("libpath/lib.js");
require(PRODUCTION ? "libpath/lib.production.js" : "libpath/lib.js");
require("libpath/lib" + (PRODUCTION ? ".production.js" : "libpath/lib.js"));
{
plugins: [
gulp.env.production ? new webpack.NormalModuleReplacementPlugin(
/libpath.lib\.js$/,
"/absoule/path/to/libpath/lib.production.js") : function() {}
]
} require("libpath/lib.js");
require("libpath/lib");
see #79 PS: Try to no use the script-loader. Use the imports-loader and the exports-loader like described here. |
@sokra Thanks for your reply! webpack = require "webpack"
module.exports =
entry: './src/index.coffee'
target: "web"
cache: yes
watch: false
module:
loaders: [
{ test: /\.coffee$/, loader: "coffee-loader" }
{ test: /\.css$/, loader: "style-loader!css-loader" }
{ test: /\.styl$/, loader: "style-loader!css-loader!stylus-loader" }
]
noParse: /\.min\.js/
output:
filename: "./www/app.js"
resolve:
extensions: ["", ".js", ".coffee"]
modulesDirectories: ['bower_components', 'node_modules']
alias:
react: "react/react.js"
fluxxor: "fluxxor/build/fluxxor.js"
plugins: [
new webpack.ProvidePlugin
React: "react"
Fluxxor: "fluxxor"
] and this is part of the result:
so where should I start? |
now It works in a totally different way: noParse:[
/\.min\.js/
path.join __dirname, bowerPath
] To replace the filename, I just change the alias like this: if gulp.env.production
conf.resolve.alias.react = "react/react.min" now (almost) everything works like expected. |
Here is how it works with react: webpack/webpack-with-common-libs@617e775
For react you can use this plugin for production. It reduces the size of the react lib to ~95kb (yes thats less than the prebuild minimized new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
}); |
sokra: does that DefinePlugin function like envify? making it easier for uglify remove the check? |
@nelix I think |
Is it possible to require a different file depending on my environment?
During the development I'd like to use
but for production use I'd like to use
I don't want to compress a lib, I just want to do s.th. like I can do with gulp:
The text was updated successfully, but these errors were encountered: