Skip to content

Commit 6a53380

Browse files
authored
Merge branch 'master' into tighter-manifest-key-prefix
2 parents 38516d0 + 86e197b commit 6a53380

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1323
-415
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
# CHANGELOG
22

3-
## 0.12.0
3+
## 0.13.0
44

55
* The `setManifestKeyPrefix()` method now forbids the key to
66
start with a `/` - #105.
77

8+
## 0.12.0
9+
10+
* Fixed a bug with webpack 3.4.0 ("Can't resolve dev") - #114.
11+
12+
* Added `--keep-public-path` option to `dev-server` that allows
13+
you to specify that you do *not* want your `publicPath` to
14+
automatically point at the dev-server URL. Also relaxed the
15+
requirements when using `dev-server` so that you *can* now
16+
specify a custom, fully-qualified `publicPath` URL - #96
17+
18+
* Fixed bug where `@import` CSS wouldn't use postcss - #108
19+
820
## 0.11.0
921

1022
* The `webpack` package was upgraded from version 2.2 to 3.1 #53. The

bin/encore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010

1111
'use strict';
1212

13-
const path = require('path');
1413
const parseRuntime = require('../lib/config/parse-runtime');
1514
const context = require('../lib/context');
1615
const chalk = require('chalk');
1716

1817
const runtimeConfig = parseRuntime(
19-
require('yargs').argv,
18+
require('yargs/yargs')(process.argv.slice(2)).argv,
2019
process.cwd()
2120
);
2221
context.runtimeConfig = runtimeConfig;
@@ -62,11 +61,14 @@ function showUsageInstructions() {
6261
console.log('Commands:');
6362
console.log(` ${chalk.green('dev')} : runs webpack for development`);
6463
console.log(' - Supports any webpack options (e.g. --watch)');
64+
console.log();
6565
console.log(` ${chalk.green('dev-server')} : runs webpack-dev-server`);
6666
console.log(` - ${chalk.yellow('--host')} The hostname/ip address the webpack-dev-server will bind to`);
6767
console.log(` - ${chalk.yellow('--port')} The port the webpack-dev-server will bind to`);
6868
console.log(` - ${chalk.yellow('--hot')} Enable HMR on webpack-dev-server`);
69+
console.log(` - ${chalk.yellow('--keep-public-path')} Do not change the public path (it is usually prefixed by the dev server URL)`);
6970
console.log(' - Supports any webpack-dev-server options');
71+
console.log();
7072
console.log(` ${chalk.green('production')} : runs webpack for production`);
7173
console.log(' - Supports any webpack options (e.g. --watch)');
7274
console.log();

fixtures/css/imports_autoprefixer.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "autoprefixer_test.css";

fixtures/css/same_filename.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
h4 {
2+
background: top left url('./../images/symfony_logo.png') no-repeat;
3+
}
4+
5+
h5 {
6+
background: top left url('./../images/same_filename/symfony_logo.png') no-repeat;
7+
}
8+
9+
@font-face {
10+
font-family: 'Roboto';
11+
src: url('./../fonts/Roboto.woff2') format('woff2');
12+
}
13+
14+
@font-face {
15+
font-family: 'Roboto2';
16+
src: url('./../fonts/same_filename/Roboto.woff2') format('woff2');
17+
}
62.8 KB
Binary file not shown.
15.6 KB
Loading

index.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ const configGenerator = require('./lib/config-generator');
1414
const validator = require('./lib/config/validator');
1515
const PrettyError = require('pretty-error');
1616
const runtimeConfig = require('./lib/context').runtimeConfig;
17+
const logger = require('./lib/logger');
1718

1819
// at this time, the encore executable should have set the runtimeConfig
1920
if (!runtimeConfig) {
2021
throw new Error('Are you trying to require index.js directly?');
2122
}
2223

2324
let webpackConfig = new WebpackConfig(runtimeConfig);
25+
if (runtimeConfig.verbose) {
26+
logger.verbose();
27+
}
2428

2529
module.exports = {
2630
/**
@@ -271,10 +275,20 @@ module.exports = {
271275
*
272276
* https://github.com/postcss/postcss-loader
273277
*
278+
* Encore.enablePostCssLoader();
279+
*
280+
* Or pass options to the loader
281+
*
282+
* Encore.enablePostCssLoader(function(options) {
283+
* // https://github.com/postcss/postcss-loader#options
284+
* // options.config = {...}
285+
* })
286+
*
287+
* @param {function} postCssLoaderOptionsCallback
274288
* @return {exports}
275289
*/
276-
enablePostCssLoader() {
277-
webpackConfig.enablePostCssLoader();
290+
enablePostCssLoader(postCssLoaderOptionsCallback = () => {}) {
291+
webpackConfig.enablePostCssLoader(postCssLoaderOptionsCallback);
278292

279293
return this;
280294
},
@@ -376,6 +390,23 @@ module.exports = {
376390
return this;
377391
},
378392

393+
/**
394+
* Call this to enable forked type checking for TypeScript loader
395+
* https://github.com/TypeStrong/ts-loader/blob/v2.3.0/README.md#faster-builds
396+
*
397+
* This is a build optimization API to reduce build times.
398+
*
399+
* @param {function} forkedTypeScriptTypesCheckOptionsCallback
400+
* @return {exports}
401+
*/
402+
enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptionsCallback = () => {}) {
403+
webpackConfig.enableForkedTypeScriptTypesChecking(
404+
forkedTypeScriptTypesCheckOptionsCallback
405+
);
406+
407+
return this;
408+
},
409+
379410
/**
380411
* If enabled, the Vue.js loader is enabled.
381412
*

lib/WebpackConfig.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class WebpackConfig {
4040
this.useVersioning = false;
4141
this.useSourceMaps = false;
4242
this.usePostCssLoader = false;
43+
this.postCssLoaderOptionsCallback = function() {};
4344
this.useSassLoader = false;
4445
this.sassLoaderOptionsCallback = function() {};
4546
this.sassOptions = {
@@ -56,6 +57,8 @@ class WebpackConfig {
5657
this.loaders = [];
5758
this.useTypeScriptLoader = false;
5859
this.tsConfigurationCallback = function() {};
60+
this.useForkedTypeScriptTypeChecking = false;
61+
this.forkedTypeScriptTypesCheckOptionsCallback = () => {};
5962
}
6063

6164
getContext() {
@@ -86,23 +89,11 @@ class WebpackConfig {
8689
}
8790

8891
setPublicPath(publicPath) {
89-
/*
90-
* Do not allow absolute URLs *and* the webpackDevServer
91-
* to be used at the same time. The webpackDevServer basically
92-
* provides the publicPath (and so in those cases, publicPath)
93-
* is simply used as the default manifestKeyPrefix.
94-
*/
95-
if (publicPath.includes('://')) {
96-
if (this.useDevServer()) {
97-
throw new Error('You cannot pass an absolute URL to setPublicPath() and use the dev-server at the same time. Try using Encore.isProduction() to only configure your absolute publicPath for production.');
98-
}
99-
} else {
100-
if (publicPath.indexOf('/') !== 0) {
101-
// technically, not starting with "/" is legal, but not
102-
// what you want in most cases. Let's not let the user make
103-
// a mistake (and we can always change this later).
104-
throw new Error('The value passed to setPublicPath() must start with "/" or be a full URL (http://...)');
105-
}
92+
if (publicPath.includes('://') === false && publicPath.indexOf('/') !== 0) {
93+
// technically, not starting with "/" is legal, but not
94+
// what you want in most cases. Let's not let the user make
95+
// a mistake (and we can always change this later).
96+
throw new Error('The value passed to setPublicPath() must start with "/" or be a full URL (http://...)');
10697
}
10798

10899
// guarantee a single trailing slash
@@ -141,13 +132,20 @@ class WebpackConfig {
141132
* @returns {string}
142133
*/
143134
getRealPublicPath() {
144-
// if we're using webpack-dev-server, use it & add the publicPath
145-
if (this.useDevServer()) {
146-
// avoid 2 middle slashes
147-
return this.runtimeConfig.devServerUrl.replace(/\/$/,'') + this.publicPath;
135+
if (!this.useDevServer()) {
136+
return this.publicPath;
137+
}
138+
139+
if (this.runtimeConfig.devServerKeepPublicPath) {
140+
return this.publicPath;
141+
}
142+
143+
if (this.publicPath.includes('://')) {
144+
return this.publicPath;
148145
}
149146

150-
return this.publicPath;
147+
// if using dev-server, prefix the publicPath with the dev server URL
148+
return this.runtimeConfig.devServerUrl.replace(/\/$/,'') + this.publicPath;
151149
}
152150

153151
addEntry(name, src) {
@@ -215,8 +213,14 @@ class WebpackConfig {
215213
this.addEntry(name, files);
216214
}
217215

218-
enablePostCssLoader() {
216+
enablePostCssLoader(postCssLoaderOptionsCallback = () => {}) {
219217
this.usePostCssLoader = true;
218+
219+
if (typeof postCssLoaderOptionsCallback !== 'function') {
220+
throw new Error('Argument 1 to enablePostCssLoader() must be a callback function.');
221+
}
222+
223+
this.postCssLoaderOptionsCallback = postCssLoaderOptionsCallback;
220224
}
221225

222226
enableSassLoader(sassLoaderOptionsCallback = () => {}, options = {}) {
@@ -255,6 +259,17 @@ class WebpackConfig {
255259
this.tsConfigurationCallback = callback;
256260
}
257261

262+
enableForkedTypeScriptTypesChecking(forkedTypeScriptTypesCheckOptionsCallback = () => {}) {
263+
264+
if (typeof forkedTypeScriptTypesCheckOptionsCallback !== 'function') {
265+
throw new Error('Argument 1 to enableForkedTypeScriptTypesChecking() must be a callback function.');
266+
}
267+
268+
this.useForkedTypeScriptTypeChecking = true;
269+
this.forkedTypeScriptTypesCheckOptionsCallback =
270+
forkedTypeScriptTypesCheckOptionsCallback;
271+
}
272+
258273
enableVueLoader(vueLoaderOptionsCallback = () => {}) {
259274
this.useVueLoader = true;
260275

0 commit comments

Comments
 (0)