Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

feat(index): add cssOutputPath option (option.cssOutputPath) #150

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a92f630
fix: outputs from useRelativePath
adriancmiranda Apr 12, 2017
e15e3a4
fix: Allowing .travis.yml file in git
adriancmiranda Apr 12, 2017
6c5f129
style: indentation
adriancmiranda Apr 12, 2017
509855d
fix: outputs
adriancmiranda Apr 12, 2017
1eb69cd
style: keeping only double quotes
adriancmiranda Apr 12, 2017
7dbce89
fix: textOutputPath parameter validation
adriancmiranda Apr 12, 2017
ffe9709
fix: normalized outputPath sep in windows os
adriancmiranda Apr 12, 2017
f2ebd86
docs: textOutputPath parameter
adriancmiranda Apr 12, 2017
d3ddff5
docs: textOutputPath parameter
adriancmiranda Apr 12, 2017
7cf4921
docs: textOutputPath parameter
adriancmiranda Apr 12, 2017
74c9e98
style: keeping only double quotes
adriancmiranda Apr 12, 2017
5c4d2a4
fix: public path from js files
adriancmiranda Apr 12, 2017
bdbb0e2
style: identation to tabs
adriancmiranda Apr 14, 2017
39b66b2
chore: removed vendor references
adriancmiranda Apr 15, 2017
4d1a43c
chore: changing textOutputPath to cssOutputPath
adriancmiranda Apr 15, 2017
3dde284
docs: changing textOutputPath to cssOutputPath
adriancmiranda Apr 15, 2017
584f009
fix: cssOutputPath defaults
adriancmiranda Apr 15, 2017
41516e5
fix: script path validation
adriancmiranda Apr 15, 2017
7b9ee2c
fix: cssOutputPath default validation
adriancmiranda Apr 15, 2017
02983bf
fix: type validation is needed to empty values
adriancmiranda Apr 15, 2017
23dffad
fix: typo
adriancmiranda Apr 15, 2017
9c62249
Merge branch 'master' into master
adriancmiranda Apr 15, 2017
17e608b
Merge branch 'master' into master
adriancmiranda Apr 16, 2017
564e84d
Merge branch 'master' of https://github.com/adriancmiranda/file-loader
adriancmiranda Apr 16, 2017
788a189
refactor: removes support for older node version
adriancmiranda Apr 18, 2017
02c8e32
refactor: strict mode
adriancmiranda Apr 18, 2017
f190ee5
docs: adding examples folder
adriancmiranda Apr 18, 2017
298a059
docs: sample improvement
adriancmiranda Apr 18, 2017
68ac897
doc: sample with dev mode
adriancmiranda Apr 18, 2017
db0596c
docs: sample with asset request from html
adriancmiranda Apr 18, 2017
1a0be65
docs: sample build fixed up
adriancmiranda Apr 19, 2017
6ea9f7e
docs: sample build fixed up
adriancmiranda Apr 19, 2017
26077c7
docs: added examples builder
adriancmiranda Apr 20, 2017
3bf2dac
test: examples compilation
adriancmiranda Apr 20, 2017
7fc4bd2
test: reporter
adriancmiranda Apr 20, 2017
c66447b
test: _module.issuer.context mockup
adriancmiranda Apr 20, 2017
3d136e3
test: webpack config mock-up
adriancmiranda Apr 21, 2017
57786c9
docs: update samples
adriancmiranda Apr 21, 2017
8e511d7
chore: recovering the file-loader icon
adriancmiranda Apr 21, 2017
8ff353f
test: cssOutputPath option
adriancmiranda Apr 21, 2017
60e3aa3
fix: output dirname rule should accept urls like ../foo/../bar
adriancmiranda Apr 21, 2017
e4b006e
fix: default publicPath
adriancmiranda May 8, 2017
1cf0f71
fix: default publicPath
adriancmiranda May 8, 2017
1cf6f67
Merge branch 'master' into master
adriancmiranda Jun 5, 2017
bf65289
feat: add option.cssOutputPath
adriancmiranda Jun 8, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintcache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\src\\cjs.js":{"size":45,"mtime":1496936755980,"hashOfConfig":"16xjw5j","results":{"filePath":"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\src\\cjs.js","messages":[],"errorCount":0,"warningCount":0}},"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\src\\helper.js":{"size":334,"mtime":1496934738398,"hashOfConfig":"16xjw5j","results":{"filePath":"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\src\\helper.js","messages":[],"errorCount":0,"warningCount":0}},"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\src\\index.js":{"size":3601,"mtime":1496941794969,"hashOfConfig":"16xjw5j","results":{"filePath":"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\src\\index.js","messages":[],"errorCount":0,"warningCount":0}},"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\test\\correct-filename.test.js":{"size":8332,"mtime":1496936927390,"hashOfConfig":"16xjw5j","results":{"filePath":"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\test\\correct-filename.test.js","messages":[],"errorCount":0,"warningCount":0}},"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\test\\optional-file-emission.test.js":{"size":628,"mtime":1496936290558,"hashOfConfig":"16xjw5j","results":{"filePath":"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\test\\optional-file-emission.test.js","messages":[],"errorCount":0,"warningCount":0}},"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\test\\helper.test.js":{"size":847,"mtime":1496949000783,"hashOfConfig":"16xjw5j","results":{"filePath":"C:\\Users\\Adrian Miranda\\Sites\\ambox\\github\\adriancmiranda\\file-loader\\test\\helper.test.js","messages":[],"errorCount":0,"warningCount":0}}}
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/node_modules
/dist
/dist
32 changes: 21 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# samples
examples/*/dist/*

# development
/node_modules
node_modules/
/coverage

logs
*.log
npm-debug.log*
yarn-debug.log*
.eslintcache
/dist
/local
/reports
.DS_Store
logs
*.log
*.log*
Thumbs.db
.idea
.vscode
*.sublime-project
*.sublime-workspace
*.sublime-workspace

# dotfiles
.*
!.babelrc
!.editorconfig
!.eslintcache
!.eslintignore
!.eslintrc
!.gitattributes
!.gitignore
!.travis.yml
*~
*#*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ use: "file-loader?name=[name].[ext]&publicPath=assets/foo/&outputPath=app/images
}
```

`cssOutputPath` also should be used (together with `useRelativePath` property) to define the output path context.
Copy link
Member

@michael-ciniawsky michael-ciniawsky Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add e.g an example here :). The current explanation is too jaded to reason about (especially for beginners)

Copy link
Contributor Author

@adriancmiranda adriancmiranda Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah, ok, I'll make a sample folder and write some tests on it. I don't know if I finish today but I'll try. Actually, I need to put the webpack, style and css loaders and ETWP. Is there any problem?

Copy link
Member

@michael-ciniawsky michael-ciniawsky Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|– src
|    |– media
|    |   |– asset...
|    |– components
|        | css...
|– dist 
|    |– bundle.js
|    |– bundle.css
|
|– webpack.config.js
|– package.json

webpack.config.js

...

{
  loader: 'file-loader'
  options: {
     useRelativePath: true,
     cssOutputPath: '...'
   }
}
...

{
    use: ExtractTextPlugin.extract({
      fallback: 'style-loader'
      use: [ 'css-loader' ]
    })
}
...

new ExtractTextPlugin()

path/to/file.(svg|png|gif|jpg)

// Example Asset

path/to/file.css

// Example CSS

bundle.css

// CSS Bundle (cssOutputPath + ETWP)

I came back here later in terms of tests 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I didn't saw your message before, so I made a little different :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is 👍 I know it's annoying but we need to get this into the docs aswell 😛

Copy link
Contributor Author

@adriancmiranda adriancmiranda Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's fine; It's fair, but I ain't finished yet. ^^
I'll come back later and then I try to write something better.

My thoughts: I'm thinking of merging these two properties (i.e. useRelativePath and cssOutputPath), does it make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging them would be a breaking change, please leave it for the moment I need to think about how to handle it at best first 😛 it maybe better a separate PR in conjunction with webpack-defaults upgrade and another semver majors e.g the general paths unification like I mentioned before

Copy link
Contributor Author

@adriancmiranda adriancmiranda Apr 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the README file:

The CSS files don't pass through the `file-loader` when they are extracted from `webpack`.
So, at this moment, we haven't access to your contexts to be compared with your own resources context to after that we generate a relative path between both.
We should manually pass the CSS output path using the `cssOutputPath` property for preventing unexpected paths.
See the examples folder to see it working.
_In case of you've multiple outputs from your CSS files, use multi-compiler or define this as `undefined`_

Is it better?


#### Filename template placeholders

* `[ext]` the extension of the resource
Expand Down
21 changes: 21 additions & 0 deletions examples/relative-path-with-multiple-css-outputs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "use-relative-path",
"author": "@adriancmiranda",
"scripts": {
"dev": "webpack-dev-server --open --env.dev",
"prebuild": "rimraf dist/",
"build": "webpack -p"
},
"optionalDependencies": {
"css-loader": "0.28.0",
"extract-text-webpack-plugin": "2.1.0",
"html-webpack-plugin": "2.28.0",
"ip": "1.1.5",
"rimraf": "2.6.1",
"style-loader": "0.16.1",
"webpack-dev-server": "2.4.2"
},
"devDependencies": {
"webpack": "2.4.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Desktop');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Mobile');
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Desktop styles */
*,
*:after,
*:before {
-webkit-tap-highlight-color: transparent;
tap-highlight-color: transparent;
box-sizing: border-box;
outline-style: none;
}

html,
body {
width: 100%;
height: 100%;
}

body {
font-family: Helvetica, sans-serif;
font-size: 16px;
line-height: 10px;
margin: 0;
}

div,
canvas {
position: absolute;
width: 100%;
height: 100%;
background-color: rgb(77, 155, 216);
}

div {
background: rgba(0,0,0,0.2) url("../../../../.github/assets/file_loader_icon.svg") no-repeat 50% 50%;
}

img {
position: absolute;
right: 10px;
bottom: 10px;
display: block;
}

div:before {
position: absolute;
display: block;
margin-top: 10px;
margin-left: 10px;
color: #fff;
content: "file-loader / examples / relative-path-with-multiple-output / desktop";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Desktop styles */
*,
*:after,
*:before {
-webkit-tap-highlight-color: transparent;
tap-highlight-color: transparent;
box-sizing: border-box;
outline-style: none;
}

html,
body {
width: 100%;
height: 100%;
}

body {
font-family: Helvetica, sans-serif;
font-size: 16px;
line-height: 10px;
margin: 0;
}

div,
canvas {
position: absolute;
width: 100%;
height: 100%;
background-color: rgb(142, 214, 251);
}

div {
background: rgba(0,0,0,0.2) url("../../../../.github/assets/file_loader_icon.svg") no-repeat 50% 50%;
}

img {
position: absolute;
right: 10px;
bottom: 10px;
display: block;
}

div:before {
position: absolute;
display: block;
margin-top: 10px;
margin-left: 10px;
color: #fff;
content: "file-loader / examples / relative-path-with-multiple-output / mobile";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<canvas id="background"></canvas>
<div>
<img src="${require(`../../../../.github/assets/file_loader_icon.svg`)}" width="30" height="30" alt="">
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<canvas id="background"></canvas>
<div>
<img src="${require(`../../../../.github/assets/file_loader_icon.svg`)}" width="30" height="30" alt="">
</div>
</body>
</html>
109 changes: 109 additions & 0 deletions examples/relative-path-with-multiple-css-outputs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const ip = require('ip');
const path = require('path');
const Text = require('extract-text-webpack-plugin');
const Html = require('html-webpack-plugin');
const webpack = require('webpack');
const fileLoader = require.resolve('../../src/cjs');

const resolve = (...args) => path.resolve(__dirname, ...args);

const OUTPUT = {
bundle: 'dist/',
img: 'media/images/',
css: 'styles/',
js: 'scripts/',
};

module.exports = (argv = {}) => {
const config = {
devtool: argv.dev ? '#cheap-module-eval-source-map' : '#source-map',
entry: {
desktop: ['./source/scripts/desktop.js', './source/styles/desktop.css'],
mobile: ['./source/scripts/mobile.js', './source/styles/mobile.css'],
},
output: {
path: resolve(OUTPUT.bundle),
filename: `${OUTPUT.js}[name].js`,
},
devServer: {
contentBase: resolve(OUTPUT.bundle),
historyApiFallback: true,
stats: 'errors-only',
host: ip.address(),
port: 3000,
},
module: {
rules: [
{
test: /\.css$/,
use: Text.extract({
publicPath: argv.dev && OUTPUT.bundle,
fallback: 'style-loader',
use: [{
loader: 'css-loader',
query: {
minimize: false,
},
}],
}),
},
{
test: /\.(jpe?g|png|gif|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: fileLoader,
options: {
useRelativePath: true,

/*
|* If you need a multiple output path for any reason
|* @see https://github.com/webpack-contrib/file-loader/issues/149#issuecomment-294290509
`*/
cssOutputPath: OUTPUT.css,

outputPath: OUTPUT.img,
name: '[name].[hash:7].[ext]',
},
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: `'${argv.dev ? 'development' : 'production'}'`,
},
}),
new Text({
filename: `${OUTPUT.css}[name]${argv.dev ? '' : '.[chunkhash]'}.css`,
disable: !!argv.dev,
allChunks: true,
}),
new Html({
title: 'file-loader // useRelativePath // mobile',
template: './source/views/mobile.html',
filename: 'mobile.html',
chunks: ['mobile'],
}),
new Html({
title: 'file-loader // useRelativePath // desktop',
template: './source/views/desktop.html',
filename: 'index.html',
chunks: ['desktop'],
}),
new webpack.HotModuleReplacementPlugin({ quiet: true }),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
],
};

if (argv.dev) {
const host = config.devServer.host;
const port = config.devServer.port;
Object.keys(config.entry).forEach((entry) => {
config.entry[entry] = [
`webpack-dev-server/client?http://${host}:${port}`,
'webpack/hot/only-dev-server',
].concat(config.entry[entry]);
});
}

return config;
};
20 changes: 20 additions & 0 deletions examples/relative-path-with-single-css-output/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "use-relative-path",
"author": "@adriancmiranda",
"scripts": {
"dev": "webpack-dev-server --open --env.dev",
"prebuild": "rimraf dist/",
"build": "webpack -p"
},
"optionalDependencies": {
"css-loader": "0.28.0",
"extract-text-webpack-plugin": "2.1.0",
"html-webpack-plugin": "2.28.0",
"rimraf": "2.6.1",
"style-loader": "0.16.1",
"webpack-dev-server": "2.4.2"
},
"devDependencies": {
"webpack": "2.4.1"
}
}
49 changes: 49 additions & 0 deletions examples/relative-path-with-single-css-output/source/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
*,
*:after,
*:before {
-webkit-tap-highlight-color: transparent;
tap-highlight-color: transparent;
box-sizing: border-box;
outline-style: none;
}

html,
body {
width: 100%;
height: 100%;
}

body {
font-family: Helvetica, sans-serif;
font-size: 16px;
line-height: 10px;
margin: 0;
}

div,
canvas {
position: absolute;
width: 100%;
height: 100%;
background-color: purple;
}

div {
background: rgba(0,0,0,0.5) url("../../../.github/assets/file_loader_icon.svg") no-repeat 50% 50%;
}

img {
position: absolute;
right: 10px;
bottom: 10px;
display: block;
}

div:before {
position: absolute;
display: block;
margin-top: 10px;
margin-left: 10px;
color: #fff;
content: "file-loader / examples / relative-path-with-single-output";
}
Loading