Skip to content

Commit 1e27937

Browse files
authored
Merge branch 'master' into webpack3
2 parents 5aec489 + efbec0d commit 1e27937

34 files changed

+1171
-63
lines changed

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# CHANGELOG
22

3+
## 0.10.0
4+
5+
* [BC BREAK] If you're using `enableSassLoader()` AND passing an options
6+
array, the options now need to be moved to the second argument:
7+
8+
```js
9+
// before
10+
.enableSassLoader({ resolve_url_loader: true });
11+
12+
// after
13+
enableSassLoader(function(sassOptions) {}, {
14+
resolve_url_loader: true
15+
})
16+
```
17+
18+
## 0.9.1
19+
20+
* Syntax error fix - #64
21+
22+
## 0.9.0
23+
24+
* [BEHAVIOR CHANGE] When using `autoProvidejQuery()`, `window.jQuery` is now also
25+
included (and so will be re-written in the compiled files). If you're also exposing
26+
`jQuery` as a global variable, you'll need to update your code:
27+
28+
```js
29+
// Before: if you had this
30+
window.jQuery = require('jquery');
31+
32+
// After: change to this
33+
global.jQuery = require('jquery');
34+
```
35+
36+
* Vue.js support! See #49
37+
38+
* Typescript support! See #50
39+
340
## 0.8.0
441

542
* Windows support fixed #28

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ feel. It aims to solve the most common Webpack use cases.
1919
## Documentation
2020

2121
[Read the Documentation on symfony.com](http://symfony.com/doc/current/frontend.html)
22+
or view a demo application: [symfony/symfony-demo](https://github.com/symfony/symfony-demo).

fixtures/js/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import render = require('./render');
2+
3+
render();

fixtures/js/render.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function render() {
2+
document.getElementById('app').innerHTML = "<h1>Welcome to Your TypeScript App</h1>";
3+
}
4+
5+
export = render;

fixtures/js/render2.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function render() {
2+
document.getElementById('app').innerHTML = "<h1>Welcome to Your TypeScript App</h1>";
3+
}
4+
5+
export = render;

fixtures/js/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"compilerOptions": {}
3+
}

fixtures/vuejs/App.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div id="app">
3+
<img src="./assets/logo.png">
4+
<hello></hello>
5+
</div>
6+
</template>
7+
8+
<script>
9+
import Hello from './components/Hello'
10+
11+
class TestClassSyntax {
12+
13+
}
14+
15+
export default {
16+
name: 'app',
17+
components: {
18+
Hello
19+
}
20+
}
21+
</script>
22+
23+
<style>
24+
#app {
25+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
26+
-webkit-font-smoothing: antialiased;
27+
-moz-osx-font-smoothing: grayscale;
28+
text-align: center;
29+
color: #2c3e50;
30+
margin-top: 60px;
31+
}
32+
</style>
33+
34+
<style lang="scss">
35+
#app {
36+
display: flex;
37+
color: #2c3e90;
38+
}
39+
</style>
40+
41+
<style lang="sass">
42+
#app
43+
color: #2c3e90
44+
</style>
45+
46+
<style lang="less">
47+
#app {
48+
margin-top: 40px;
49+
}
50+
</style>

fixtures/vuejs/assets/logo.png

6.69 KB
Loading

fixtures/vuejs/components/Hello.vue

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<div class="hello">
3+
<h1>{{ msg }}</h1>
4+
<h2>Essential Links</h2>
5+
<ul>
6+
<li><a href="https://vuejs.org" target="_blank">Core Docs</a></li>
7+
<li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li>
8+
<li><a href="https://gitter.im/vuejs/vue" target="_blank">Gitter Chat</a></li>
9+
<li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li>
10+
<br>
11+
<li><a href="http://vuejs-templates.github.io/webpack/" target="_blank">Docs for This Template</a></li>
12+
</ul>
13+
<h2>Ecosystem</h2>
14+
<ul>
15+
<li><a href="http://router.vuejs.org/" target="_blank">vue-router</a></li>
16+
<li><a href="http://vuex.vuejs.org/" target="_blank">vuex</a></li>
17+
<li><a href="http://vue-loader.vuejs.org/" target="_blank">vue-loader</a></li>
18+
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank">awesome-vue</a></li>
19+
</ul>
20+
</div>
21+
</template>
22+
23+
<script>
24+
export default {
25+
name: 'hello',
26+
data () {
27+
return {
28+
msg: 'Welcome to Your Vue.js App'
29+
}
30+
}
31+
}
32+
</script>
33+
34+
<!-- Add "scoped" attribute to limit CSS to this component only -->
35+
<style scoped>
36+
h1, h2 {
37+
font-weight: normal;
38+
}
39+
40+
ul {
41+
list-style-type: none;
42+
padding: 0;
43+
}
44+
45+
li {
46+
display: inline-block;
47+
margin: 0 10px;
48+
}
49+
50+
a {
51+
color: #42b983;
52+
}
53+
</style>

fixtures/vuejs/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './App'
3+
4+
new Vue({
5+
el: '#app',
6+
template: '<App/>',
7+
components: { App }
8+
})

index.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (!runtimeConfig) {
2020
throw new Error('Are you trying to require index.js directly?');
2121
}
2222

23-
const webpackConfig = new WebpackConfig(runtimeConfig);
23+
let webpackConfig = new WebpackConfig(runtimeConfig);
2424

2525
module.exports = {
2626
/**
@@ -282,6 +282,18 @@ module.exports = {
282282
/**
283283
* Call this if you plan on loading SASS files.
284284
*
285+
* Encore.enableSassLoader();
286+
*
287+
* Or pass options to node-sass
288+
*
289+
* Encore.enableSassLoader(function(options) {
290+
* // https://github.com/sass/node-sass#options
291+
* // options.includePaths = [...]
292+
* }, {
293+
* // set optional Encore-specific options
294+
* // resolve_url_loader: true
295+
* });
296+
*
285297
* Supported options:
286298
* * {bool} resolve_url_loader (default=true)
287299
* Whether or not to use the resolve-url-loader.
@@ -291,11 +303,12 @@ module.exports = {
291303
* to the original entry file... not whatever file
292304
* the url() appears in.
293305
*
294-
* @param {object} options
306+
* @param {function} sassLoaderOptionsCallback
307+
* @param {object} encoreOptions
295308
* @return {exports}
296309
*/
297-
enableSassLoader(options = {}) {
298-
webpackConfig.enableSassLoader(options);
310+
enableSassLoader(sassLoaderOptionsCallback = () => {}, encoreOptions = {}) {
311+
webpackConfig.enableSassLoader(sassLoaderOptionsCallback, encoreOptions);
299312

300313
return this;
301314
},
@@ -330,7 +343,8 @@ module.exports = {
330343
},
331344

332345
/**
333-
* If enabled, the react preset is added to Babel:
346+
* If enabled, the react preset is added to Babel.
347+
*
334348
* https://babeljs.io/docs/plugins/preset-react/
335349
*
336350
* @returns {exports}
@@ -341,6 +355,47 @@ module.exports = {
341355
return this;
342356
},
343357

358+
/**
359+
* Call this if you plan on loading TypeScript files.
360+
*
361+
* Encore.enableTypeScriptLoader()
362+
*
363+
* Or, configure the ts-loader options:
364+
*
365+
* Encore.enableTypeScriptLoader(function(tsConfig) {
366+
* // https://github.com/TypeStrong/ts-loader/blob/master/README.md#loader-options
367+
* // tsConfig.silent = false;
368+
* });
369+
*
370+
* @param {function} callback
371+
* @return {exports}
372+
*/
373+
enableTypeScriptLoader(callback = () => {}) {
374+
webpackConfig.enableTypeScriptLoader(callback);
375+
},
376+
377+
/**
378+
* If enabled, the Vue.js loader is enabled.
379+
*
380+
* https://github.com/vuejs/vue-loader
381+
*
382+
* Encore.enableVueLoader();
383+
*
384+
* // or configure the vue-loader options
385+
* // https://vue-loader.vuejs.org/en/configurations/advanced.html
386+
* Encore.enableVueLoader(function(options) {
387+
* options.preLoaders = { ... }
388+
* });
389+
*
390+
* @param {function} vueLoaderOptionsCallback
391+
* @returns {exports}
392+
*/
393+
enableVueLoader(vueLoaderOptionsCallback = () => {}) {
394+
webpackConfig.enableVueLoader(vueLoaderOptionsCallback);
395+
396+
return this;
397+
},
398+
344399
/**
345400
* If enabled, the output directory is emptied between
346401
* each build (to remove old files).
@@ -356,7 +411,7 @@ module.exports = {
356411
/**
357412
* Is this currently a "production" build?
358413
*
359-
* @returns {*}
414+
* @returns {boolean}
360415
*/
361416
isProduction() {
362417
return webpackConfig.isProduction();
@@ -381,5 +436,17 @@ module.exports = {
381436
console.log(pe.render(error));
382437
process.exit(1); // eslint-disable-line
383438
}
439+
},
440+
441+
/**
442+
* Resets the Encore state to allow building a new config.
443+
*
444+
* getWebpackConfig should be used before resetting to build
445+
* a config for the existing state.
446+
*
447+
* @returns {void}
448+
*/
449+
reset() {
450+
webpackConfig = new WebpackConfig(runtimeConfig);
384451
}
385452
};

lib/WebpackConfig.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class WebpackConfig {
4141
this.useSourceMaps = false;
4242
this.usePostCssLoader = false;
4343
this.useSassLoader = false;
44+
this.sassLoaderOptionsCallback = function() {};
4445
this.sassOptions = {
4546
resolve_url_loader: true
4647
};
@@ -50,7 +51,11 @@ class WebpackConfig {
5051
this.providedVariables = {};
5152
this.babelConfigurationCallback = function() {};
5253
this.useReact = false;
54+
this.useVueLoader = false;
55+
this.vueLoaderOptionsCallback = () => {};
5356
this.loaders = [];
57+
this.useTypeScriptLoader = false;
58+
this.tsConfigurationCallback = function() {};
5459
}
5560

5661
getContext() {
@@ -202,9 +207,15 @@ class WebpackConfig {
202207
this.usePostCssLoader = true;
203208
}
204209

205-
enableSassLoader(options = {}) {
210+
enableSassLoader(sassLoaderOptionsCallback = () => {}, options = {}) {
206211
this.useSassLoader = true;
207212

213+
if (typeof sassLoaderOptionsCallback !== 'function') {
214+
throw new Error('Argument 1 to enableSassLoader() must be a callback function.');
215+
}
216+
217+
this.sassLoaderOptionsCallback = sassLoaderOptionsCallback;
218+
208219
for (const optionKey of Object.keys(options)) {
209220
if (!(optionKey in this.sassOptions)) {
210221
throw new Error(`Invalid option "${optionKey}" passed to enableSassLoader(). Valid keys are ${Object.keys(this.sassOptions).join(', ')}`);
@@ -222,6 +233,26 @@ class WebpackConfig {
222233
this.useReact = true;
223234
}
224235

236+
enableTypeScriptLoader(callback = () => {}) {
237+
this.useTypeScriptLoader = true;
238+
239+
if (typeof callback !== 'function') {
240+
throw new Error('Argument 1 to enableTypeScriptLoader() must be a callback function.');
241+
}
242+
243+
this.tsConfigurationCallback = callback;
244+
}
245+
246+
enableVueLoader(vueLoaderOptionsCallback = () => {}) {
247+
this.useVueLoader = true;
248+
249+
if (typeof vueLoaderOptionsCallback !== 'function') {
250+
throw new Error('Argument 1 to enableVueLoader() must be a callback function.');
251+
}
252+
253+
this.vueLoaderOptionsCallback = vueLoaderOptionsCallback;
254+
}
255+
225256
cleanupOutputBeforeBuild() {
226257
this.cleanupOutput = true;
227258
}
@@ -244,6 +275,7 @@ class WebpackConfig {
244275
this.autoProvideVariables({
245276
$: 'jquery',
246277
jQuery: 'jquery',
278+
'window.jQuery': 'jquery',
247279
});
248280
}
249281

0 commit comments

Comments
 (0)