This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the loader API
this.loadModule()
Refs GH-66
- Loading branch information
Showing
10 changed files
with
166 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
@import "./main"; | ||
|
||
.less { | ||
color: red; | ||
color: @color-red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "./variables/variables"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@color-red: red; | ||
@color-gray: #77808b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var path = require('path'); | ||
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
var webpack = require('webpack'); | ||
|
||
module.exports = { | ||
entry: path.resolve(__dirname, 'src/index.js'), | ||
output: { | ||
path: path.resolve(__dirname, 'dist--raw'), | ||
filename: '[name].js' | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
loader: 'babel' | ||
}, { | ||
test: /\.less$/, | ||
loader: ExtractTextPlugin.extract({ | ||
fallbackLoader: 'style', | ||
loader: 'css!less' | ||
}) | ||
}, { | ||
test: /\.scss$/, | ||
loader: ExtractTextPlugin.extract({ | ||
fallbackLoader: 'style', | ||
loader: 'css!sass' | ||
}) | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.optimize.OccurrenceOrderPlugin(), | ||
new ExtractTextPlugin('styles.css'), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var fs = require('fs'); | ||
var multiline = require('multiline-slash'); | ||
var webpack = require('webpack'); | ||
var assert = require('chai').assert; | ||
var HappyPlugin = require('../../HappyPlugin'); | ||
var TestUtils = require('../../HappyTestUtils'); | ||
|
||
describe('[Integration] Loader RPCs - this.loadModule()', function() { | ||
var testSuite = TestUtils.IntegrationSuite2(this); | ||
|
||
it('works', function(done) { | ||
var loader = testSuite.createLoaderFromString(multiline(function() { | ||
// module.exports = function() { | ||
// var callback = this.async(); | ||
// | ||
// this.loadModule('./b.js', function(err, contents) { | ||
// if (err) { | ||
// return callback(err); | ||
// } | ||
// | ||
// callback(null, '// loaded file: "' + contents + '";'); | ||
// }); | ||
// }; | ||
})); | ||
|
||
var file1 = testSuite.createFile('src/a.js', '// a.js'); | ||
testSuite.createFile('src/b.js', 'lolol'); | ||
|
||
var compiler = webpack({ | ||
entry: file1.path, | ||
|
||
output: { | ||
path: testSuite.createDirectory('dist').path, | ||
}, | ||
|
||
module: { | ||
loaders: [{ | ||
test: file1.path, | ||
loader: TestUtils.HAPPY_LOADER_PATH | ||
}] | ||
}, | ||
|
||
plugins: [ | ||
new HappyPlugin({ | ||
loaders: [ loader.path ], | ||
}) | ||
] | ||
}); | ||
|
||
compiler.run(function(err, rawStats) { | ||
if (TestUtils.assertNoWebpackErrors(err, rawStats, done)) { | ||
return; | ||
} | ||
|
||
assert.match( | ||
fs.readFileSync(testSuite.resolve('dist/bundle.js'), 'utf-8'), | ||
'// loaded file: "lolol";' | ||
); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |