Skip to content
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

scss - import not removed from bundle #3052

Closed
DaveO-Home opened this issue May 17, 2019 · 9 comments
Closed

scss - import not removed from bundle #3052

DaveO-Home opened this issue May 17, 2019 · 9 comments
Labels

Comments

@DaveO-Home
Copy link

❔ Question

Using import "./scss/index.scss"; bundle has require("./scss/index.scss"); and when the bundle is loaded expects the file to exist on the server. The css has already been produced and is loaded properly. So, why does the ".scss" file have to be visible?

🔦 Context

Using gulp to build -
const options = {
production: isProduction,
outDir: '../' + dist,
contentHash: false,
outFile: isProduction ? 'index.html' : 'index_dev.html',
publicUrl: watch ? '' : './',
watch: watch,
cache: !isProduction,
cacheDir: '.cache',
minify: isProduction,
target: 'browser',
https: false,
logLevel: 3,
sourceMaps: !isProduction,
detailedReport: isProduction
};

Must provide .scss file on production server

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Node 10.15.3
npm/Yarn 6.9
Operating System Fedora 30
@mischnic
Copy link
Member

mischnic commented May 28, 2019

The JS bundle says require("./scss/index.scss"); but it really only loads the css file and if I read your post correctly, that works correctly.

Your issue is that the JS bundle still contains .scss? Why is this a problem?
Or are you asking why the require call is needed at all?

@DaveO-Home
Copy link
Author

It also attempts to load the .scss file, that is the problem. I have to deploy an empty index.scss to the server.

@mischnic
Copy link
Member

It also attempts to load the .scss file, that is the problem.

Could you create a minimal example when this happens?

@DaveO-Home
Copy link
Author

@mischnic Ok, it does work. However, I'm using parceljs to build a library. Then in an app I use Browserify to build. Apparently, browserify interprets the 'require' as commonjs?.... Close if parcel does not support something like this.

@mischnic
Copy link
Member

Apparently, browserify interprets the 'require' as commonjs?.... Close if parcel does not support something like this.

Webpack and browserify both think the require that. Here's a similar issue: #2883

The library you built with parcel contains a line like this (for a non minified bundle parcel build --no-minify src/index.js:

var nodeRequire = typeof require === 'function' && require;

Could you try replacing that with

var nodeRequire = null;

and testing how browserify behaves then?

@DaveO-Home
Copy link
Author

@mischnic - var nodeRequire = null does not work. However, if I delete the line;
require("../scss/index.scss");
it works perfectly.

@mischnic
Copy link
Member

Ok, I'll have to investigate how we can make webpack and browserify ignore the requires emitted by parcel...

I'll close this issue because it's caused by the same underlying problem as #2883

@mischnic
Copy link
Member

mischnic commented Jun 2, 2019

Note, I strongly advise not using Parcel's feature of importing style in a library. Reasons:

  1. The bundler of the end user doesn't know that the style file is needed at runtime
  2. (more importantly) Might be surprising to see a css file being loaded all of the sudden

@DaveO-Home
Copy link
Author

DaveO-Home commented Jun 3, 2019

@mischnic - Yes I did that as my work around. Works fine. There is one other issue with using Parcel to build a library. The bundle scopes parcelRequire=function to window. This does not work with "Rollup". I changed it to var parcelRequire=function without any side effects. Works in all tested bundlers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants