question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile both minified & non-minified JS/SASS files for production?

See original GitHub issue

Hello,

Is there a way to compile both minified and non-minified JS and SASS files for production?

For example:

- src/app.js   => dist/app.js  => dist/app.min.js
- src/app.scss => dist/app.css => dist/app.min.css

This would be very handy when creating packages.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
tpraxlcommented, Oct 12, 2017

Actually – after trying to modify mix to make that possible – I noticed that it is already possible. You just need the correct configuration.

Here are the required changes to webpack.mix.js in order to produce both: *.min.js and *.js. I don’t understand why, because the CustomTasksPlugin should minify the tasks’ assets nonetheless (see my research above), but somehow it doesn’t in this case:

mix.options(
   {
      // publicPath is optional. But if you don't specify it, you may need to adapt the path for mix.minify()
      publicPath: 'dist/',
      // set uglify to false in order to prevent production minification
      // it prevents mix from pushing UglifyJSPlugin into the webpack config
      uglify: false
   }
);

mix.js('src/index.js', 'app.js');

// you usually only want to minify this in production
if(mix.inProduction()) {
   mix.minify('dist/app.js');
}

Result: app.js (not minified) and app.min.js (minified) are created during production ( yarn run production or npm run production).

[EDIT] This will only work for js files. Not for scss / css.

1reaction
ivanvermeyencommented, Apr 25, 2017

For production I only compile a minified version with the .min suffix at the moment:

mix.js('src/js/app.js', 'public/js/app.min.js')
    .sass('src/scss/app.scss', 'public/css/app.min.css');

I also wanted to add a compiled, but not minified CSS and JS file to my package. In case people want to edit the CSS but don’t use mix or grunt or gulp or something. But maybe that’s not really necessary…

So what I mean is that in the end I have 3 versions of my CSS and JS:

  1. source files (SASS/ECMAScript6/…)
  2. compiled and minified for production
  3. compiled but not minified

But again, after thinking about it maybe it’s not all that useful…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Mix: Exclude SASS File from Minifying for Production
I am running Laravel 5.4 and using Laravel Mix to compile my assets. I have two SASS files for production. However, one of...
Read more >
Laravel mix: how to exclude a SASS file from minifying for production
Hi folks, So I am running Laravel 5.4 and using Laravel Mix to compile my assets. I have two sass files for production,...
Read more >
Laravel mix: how to exclude a SASS file from minifying?
So I am running Laravel 5.4 and using Laravel Mix to compile my assets. I have two sass files for production, however, one...
Read more >
How to compile Sass files in Visual Studio and Webpack
How to compile Sass files in Visual Studio and Webpack ... Our discussion will include minification and autoprefixing for production.
Read more >
SASS & SCSS Compiling/Building with Hugo and Bootstrap ...
To try and shrink that HTML file, the dash, dash minify. We'll save that and we'll check them out. So you'll see at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found